FINDSTR

Posted in Programming/batch by

 

정규식을 사용하여 파일내의 특정 단어를 검색한다

 

예제1> 파일 내에서 단어를 검색

findstr sentence file_name

 

예제2> 현재 폴더의 모든 txt 파일에서 senetence 가 들어있는 파일 검색 후, 그 파일 이름 출력

FOR /f %%a in ('FINDSTR /m sentence *.txt') do (
       echo %%a
)

parameters

/b : Matches the pattern if at the beginning of a line.

/e : Matches the pattern if at the end of a line.

/l : Uses search strings literally.

/r : Uses search strings as regular expressions. Findstr interprets all metacharacters as regular expressions unless you use /l.

/s : Searches for matching files in the current directory and all subdirectories.

/i : Specifies that the search is not to be case-sensitive.

/x : Prints lines that match exactly.

/v : Prints only lines that do not contain a match.

/n : Prints the line number before each line that matches.

/m : Prints only the file name if a file contains a match.

/o : Prints seek offset before each matching line.

/p : Skips files with non-printable characters.

/offline : Processes files with offline attribute set.

/f: file : Reads file list from the specified file.

/c: string : Uses specified text as a literal search string.

/g: file : Gets search strings from the specified file.

/d: dirlist : Searches a comma-delimited list of directories.

/a: ColorAttribute : Specifies color attributes with two hexadecimal digits.

strings : Specified text to be searched for in FileName.

[ Drive : ][ Path ] FileName [...] : Specifies a file or files to search.

/? : Displays help at the command prompt.

 

Reference

http://technet.microsoft.com/en-us/library/bb490907.aspx