ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • grep
    Util 2016. 6. 24. 18:08

    grep (g/re/p)


    $ grep [-옵션] 패턴 파일명

    e.g.

    $ grep -r '삼성' *

    ## 현재 디렉토리 및 서브디렉토리의 모든 파일에서 '삼성' 이라는 패턴이 들어간 문자열 출력


    - Windows

    기본사용법 : findstr /?

    ■ PoolMon.exe 를 사용할때.. 커널드라이버 Tag 검색

    findstr /m /l "BcMc" c:\windows\system32\drivers\*.sys

     

    ■ 특정 문자열 검색

    findstr 문자열1 document.txt

    findstr "문자열1 문자열2" document.txt 

    findstr /c:"똑같은 문자열만 찾아주세요" document.txt

     

    ■ W로 시작해서 ws로 끝나는 문자열 검색

    findstr "W.*ws" document.txt

     

    ■ C: 드라이브와 하위폴더에서 문자열 검색 (대소문자 불문)

    findstr /s /i 문자열1 C:\*.*

     

    ■ 파일목록내에 문자열 검색하기

    findstr /f:C:\files.txt /m /l "BcMc"

    findstr /g:argument.txt /f:files.txt



    사용 방법 :

     

    findstr "찾고싶은 문자" *  --> findstr "check" *

     

    이렇게 하면 현재 위치한 디렉토리에서만 모든 파일에서 check가 포함도니 라인을 출력해 줍니다.

    그런데 이게 몇번째 라인인지 알 수가 없으니 grep 처럼 나타내 주기 위해서 /N 옵션을 붙여 줍니다.

     

    findstr /N "check" *

     

    하위 폴더까지 검색하고 싶다? 

     

    findstr /N /S "check" *

     

    모든 파일을 다 검색하니 느려터진다. 특정 파일만 필터해서 검색하고 싶다면?

     

    findstr /N /S "check" *.txt

     

    요런 식으로 사용하면 된다.



    참조 사이트:

    http://ra2kstar.tistory.com/100

    http://www.dreamy.pe.kr/zbxe/CodeClip/164827

    http://jjjryu.tistory.com/entry/GnuWin32

    http://jjjryu.tistory.com/entry/%EC%A0%95%EA%B7%9C%EC%8B%9D

    http://jjjryu.tistory.com/entry/%EC%8A%A4%ED%8A%B8%EB%A6%BC-%ED%8E%B8%EC%A7%91%EA%B8%B0SED-stream-editor


Designed by Tistory.