사용자 도구

사이트 도구


linux:grep

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
linux:grep [2016/08/08 15:54]
kwon37xi [특정 파일명에서 문자열 찾기]
linux:grep [2021/08/24 13:54]
kwon37xi
줄 2: 줄 2:
  
 ===== 특정 파일명에서 문자열 찾기 ===== ===== 특정 파일명에서 문자열 찾기 =====
-  * [[http://www.cyberciti.biz/faq/unix-linux-grep-include-file-pattern-recursive-example/|grep include file pattern recursive example]]<code sh>+<code sh> 
 +# 현재 디렉토리 파일 한정 
 +grep <pattern> <file> 
 +</code> 
 + 
 +  * [[http://www.cyberciti.biz/faq/unix-linux-grep-include-file-pattern-recursive-example/|grep include file pattern recursive example]] 
 +<code sh> 
 +# 하위 디렉토리를 포함하려면 -R --include=GLOB 을 사용
 # grep -R --include=GLOB "pattern" /path/to/dir # grep -R --include=GLOB "pattern" /path/to/dir
 grep -R --include="*.txt" "pattern" /path/to/dir grep -R --include="*.txt" "pattern" /path/to/dir
줄 23: 줄 30:
   * ''-B [줄수]'' : 매칭 되는 라인의 위로 줄 수만큼 더 보여줌   * ''-B [줄수]'' : 매칭 되는 라인의 위로 줄 수만큼 더 보여줌
   * ''-C [줄수]'' : ''-A''와 ''-B'' 둘 다 적용   * ''-C [줄수]'' : ''-A''와 ''-B'' 둘 다 적용
 +
 +===== 여러 단어 검색 =====
 +  * [[https://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/|Search Multiple Words / String Pattern Using grep Command on Bash shell - nixCraft]]
 +<code sh>
 +grep 'word1\|word2\|word3' /path/to/file
 +### Search all text files ###
 +grep 'word*' *.txt
 +### Search all python files for 'wordA' or 'wordB' ###
 +grep 'wordA*'\''wordB' *.py
 +grep -E 'word1|word2' *.doc
 +grep -e string1 -e string2 *.pl
 +egrep "word1|word2" *.c
 +</code>
  
 ===== 기타 옵션 ===== ===== 기타 옵션 =====
줄 29: 줄 49:
 ===== grep 대체 ===== ===== grep 대체 =====
   * [[linux:ack|ack - beyond grep]]   * [[linux:ack|ack - beyond grep]]
 +  * [[linux:silver_searcher|The Silver Searcher - ag]]
   * [[https://github.com/ggreer/the_silver_searcher|The silver searcher]]   * [[https://github.com/ggreer/the_silver_searcher|The silver searcher]]
   * [[https://github.com/monochromegane/the_platinum_searcher|The Platinum searcher]]   * [[https://github.com/monochromegane/the_platinum_searcher|The Platinum searcher]]
   * [[http://betterthanack.com/|Better Than Ack]]   * [[http://betterthanack.com/|Better Than Ack]]
linux/grep.txt · 마지막으로 수정됨: 2023/05/15 17:03 저자 kwon37xi