본문으로 바로가기


Windows에서 grep 하기(find, findstr)



윈도우환경에서 리눅스의 grep 명령어와 같은 동작을 하는 명령어 = find(기본), findstr(확장)

 

[Find 명령어]

find "(찾을 문자)" (경로) *  ( find "hello" c:\note * )

= c:\note 디렉토리의 모든 파일에서 "hello"가 포함된 라인을 출력

 

find /N "hello" c:\note *

= 파일에서 탐지된 "hello" 문자가 몇번째 라인인지 알고싶을 때

 

 find /N /I "hello" c:\note *

= 대소문자 구분 없이 찾고 싶을 때

 

 

[Findstr 명령어]

findstr "(찾을 문자)" (경로) *  ( findstr "hello" c:\note * )

= c:\note 디렉토리의 모든 파일에서 "hello"가 포함된 라인을 출력

 

findstr /N "hello" c:\note *

= 파일에서 탐지된 "hello" 문자가 몇번째 라인인지 알고싶을 때

 

findstr /N /S "hello" c:\note *

= 하위 폴더까지 검색할 때

 

findstr /N /S "hello" *.txt

= 특정 확장자 파일만 검색할 때

 

 

[응용]

= dir c:\note | find /N /I "hello"

= ipconfig | findstr "게이트웨이"