Windows 재귀 GREP 명령줄
Windows 에서는 재귀적인 grep 를 실행할 필요가 있습니다.유닉스/Linux 에서는 다음과 같습니다.
grep -i 'string' `find . -print`
또는 보다 정확한 방법:
find . -print | xargs grep -i 'string'
cmd.exe에만 의존하기 때문에 Windows에 내장된 명령어밖에 없습니다.안타깝게도 이 서버에 Cygwin이나 UnxUtils와 같은 서드파티 도구를 설치할 수 없습니다.PowerShell을 설치할 수 있는지도 잘 모르겠습니다.내장 cmd.exe만 사용하는 방법(Windows 2003 Server)이 있습니까?
findstr는 재귀 검색(/S)을 실행할 수 있으며 정규식 구문(/R)의 일부 변형을 지원합니다.
C:\>findstr /?
Searches for strings in files.
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]
/B Matches pattern if at the beginning of a line.
/E Matches pattern if at the end of a line.
/L Uses search strings literally.
/R Uses search strings as regular expressions.
/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 filename if a file contains a match.
/O Prints character offset before each matching line.
/P Skip files with non-printable characters.
/OFF[LINE] Do not skip files with offline attribute set.
/A:attr Specifies color attribute with two hex digits. See "color /?"
/F:file Reads file list from the specified file(/ stands for console).
/C:string Uses specified string as a literal search string.
/G:file Gets search strings from the specified file(/ stands for console).
/D:dir Search a semicolon delimited list of directories
strings Text to be searched for.
[drive:][path]filename
Specifies a file or files to search.
Use spaces to separate multiple search strings unless the argument is prefixed
with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.
Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\<xyz Word position: beginning of word
xyz\> Word position: end of word
For full information on FINDSTR regular expressions refer to the online Command
Reference.
findstr /spin /c:"string" [files]
파라미터의 의미는 다음과 같습니다.
s= 재귀적p=는 인쇄할 수 없는 문자를 건너뜁니다.i= 대소문자를 구분하지 않음n= 라인 번호 인쇄
검색할 문자열은 따옴표 안에 있는 비트입니다./c:
지정된 '검색 텍스트'를 포함하는 모든 파일 이름을 나열하는 다음 명령을 사용하여 텍스트를 검색했습니다.
C:\Users\ak47\Desktop\trunk>findstr /S /I /M /C:"search text" *.*
재귀 검색import속마음src폴더:
> findstr /s import .\src\*
정말 훌륭한 툴을 추천합니다.
네이티브 unix 유틸리티:
포장을 풀고 PATH 환경변수에 폴더를 넣고 voila! : )
마법처럼 작동하며, GREP 말고도 훨씬 더 많은 것이 있습니다;)
for /f %G in ('dir *.cpp *.h /s/b') do ( find /i "what you search" "%G") >> out_file.txt
Select-String나한테 가장 잘 먹혔어여기에 나열된 기타 모든 옵션:findstr큰 파일에서는 동작하지 않았습니다.
다음은 예를 제시하겠습니다.
select-string -pattern "<pattern>" -path "<path>"
주의: 여기에는 Powershell이 필요합니다.
Perl 을 인스톨 하고 있는 경우는, http://beyondgrep.com/ 에서 구할 수 있는ack 를 사용할 수 있습니다.
"findstr /spin /c:"string" [[drive:][path]path[...]"
위에서 두 번째로 높은 답변(2009년 3월 30일 22:26에 i_am_jorf에 의해)과 유사합니다.이 예에서는 "findstr /spin /c:"string [ files ]가 표시됩니다.
그러나 "findstr /?"를 실행하면 [files]로 정의된 옵션이나 파라미터가 없음을 나타냅니다.여기서 의미하는 것은 "findstr /?"가 나타내는 "[drive:][path]filename[...]]"을 정의하는 파라미터입니다.이 파라미터는 나중에 [drive:][path]filename] - 검색할 파일을 지정합니다.
따라서 개인 단문을 사용하지 않도록 특정 파일을 검색할 때 findstr />가 정의하는 방법으로 제공합니다.[ findstr / spin / c : " string " [[ drive : ][ path ]filename [ ... ]
언급URL : https://stackoverflow.com/questions/698038/windows-recursive-grep-command-line
'source' 카테고리의 다른 글
| 클라우드 프로젝트를 빌드할 때 "객체 참조가 객체의 인스턴스로 설정되지 않음" (0) | 2023.04.22 |
|---|---|
| Enum을 ASP의 DropDownList 컨트롤에 바인드하려면 어떻게 해야 합니다.인터넷? (0) | 2023.04.22 |
| 환경변수를 인쇄/반향하는 방법 (0) | 2023.04.22 |
| Excel VBA - 범위전치 페이스트 복사 (0) | 2023.04.22 |
| XAML에서의 TimeSpan 포맷 방법 (0) | 2023.04.22 |