text pattern 찾는 명령어..

aw2310의 이미지

특정한 pattern을 찾는 명령어를 알고 싶습니다.
grep을 어떻게 사용해서 하면 될것 같은데요..

어떤 특정 디렉토리 밑에 있는 모든 문서들 중에
파일 확장자가 *.cpp와 *.h인 파일 들 중에서
파일 내용으로 'KKK'라는 패턴을 포함하고 있는 파일들의
목록을 나열하고자 한다.

이때 사용하는 명령어는?

누가 가르쳐줘서 'grep -r pattern' 이라는
명령어를 써봤는데.. 하위 디렉토리의 모든 파일들
*.o 나 실행바이너리들 모두를 검색하느라
시간이 너무 많이 걸리네요.. 특정한 이름(확장자)의
파일들에서만 검색할 수 있는 방법을 알고 싶습니다.

그럼.. 미리 감사드립니다..

정태영의 이미지

grep -R KKK ./*.cpp

오랫동안 꿈을 그리는 사람은 그 꿈을 닮아간다...

http://mytears.org ~(~_~)~
나 한줄기 바람처럼..

elanoia의 이미지

grep -rn pattern *.cpp *.h

음... 이제 부터 생각해 봐야겠다.

aw2310의 이미지

위에 답변 주신 두분 방법 모두
못찾습니다.

제가 오타 친것도 아니고..

윈도우 탐색기(삼바로 연결됐음)로 검색해보면
찾는데... 위의 두가지 명령어로는 못찾네요..

[aw2310@cnode1 ~/work/LGCF]$ grep -R LGCF_ComponentFinder ./*.cpp
grep: ./*.cpp: 그런 파일이나 디렉토리가 없음
[Exit 2]
[aw2310@cnode1 ~/work/LGCF]$ grep -rn LGCF_ComponentFinder *.cpp
grep: *.cpp: 그런 파일이나 디렉토리가 없음
[Exit 2]

windower의 이미지

[windower@pxa255 sample1]$ grep -nr GFP_KERNEL ./*.c
29:     tester = (struct test_structure *)kmalloc(sizeof(struct test_structure), GFP_KERNEL);

[windower@pxa255 sample1]$ grep -nr LGCF_ComponentFinder ./*.cpp
5:      LGCF_ComponentFinder = 0x123;
[windower@pxa255 sample1]$

이상하군요 잘 찾아지는 것 같습니다만..

Always

dangsan49의 이미지

음...이건
find 와 grep의 조합으로 하면 금방 될것 같다는 예감이....

find . -name "*.[ch]" -exec grep pattern {} \;

근데 결국 grep -r 와 차이가 없어지냥 ?

VENI, VIDI, VICI - Caesar, Gaius Julius -

elanoia의 이미지

azure@assp_svr:~/Program/SystemC$ cat main.cpp
#include "half_adder.h"

int sc_main(int argc, char* argv[])
{
        sc_start(100, SC_NS);

        return 0;
}


azure@assp_svr:~/Program/SystemC$ grep -rn "int" *.cpp
main.cpp:3:int sc_main(int argc, char* argv[])

azure@assp_svr:~/Program/SystemC$ grep -rn int *.cpp
main.cpp:3:int sc_main(int argc, char* argv[])

azure@assp_svr:~/Program/SystemC$ grep -rn int ./*.cpp
./main.cpp:3:int sc_main(int argc, char* argv[])

별 문제는 없어 보입니다만....

^^;

음... 이제 부터 생각해 봐야겠다.