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[])

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

^^;

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

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.