再去看看 windows中 类似于grep的命令
windows grep
C:\Users\xx>ipconfig /all | findstr 192. IPv4 地址 . . . . . . . . . . . . : 192.168.31.119(首选) 默认网关. . . . . . . . . . . . . : 192.168.31.1 DHCP 服务器 . . . . . . . . . . . : 192.168.31.1 DNS 服务器 . . . . . . . . . . . : 192.168.31.1

【总结】
Windows中,类似于Linux中grep的命令是 findstr
语法
findstr [/b] [/e] [/l | /r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/f:<File>] [/c:<String>] [/g:<File>] [/d:<DirList>] [/a:<ColorAttribute>] [/off[line]] <Strings> [<Drive>:][<Path>]<FileName>[ ...]
参数:
- /b Matches the text pattern if it is at the beginning of a line.
- /e Matches the text pattern if it is at the end of a line.
- /l Processes search strings literally.
- /r Processes search strings as regular expressions. This is the default setting.
- /s Searches the current directory and all subdirectories.
- /i Ignores the case of the characters when searching for the string.
- /x Prints lines that match exactly.
- /v Prints only lines that do not contain a match.
- /n Prints the line number of each line that matches.
- /m Prints only the file name if a file contains a match.
- /o Prints character offset before each matching line.
- /p Skips files with non-printable characters.
- /off[line] Does not skip files that have the offline attribute set.
- /f:<File> Gets a file list from the specified file.
- /c:<String> Uses the specified text as a literal search string.
- /g:<File> Gets search strings from the specified file.
- /d:<DirList> Searches the specified list of directories. Each directory must be separated with a semicolon (;), for example dir1;dir2;dir3.
- /a:<ColorAttribute> Specifies color attributes with two hexadecimal digits. Type color /? for additional information.
- <Strings> Specifies the text to search for in FileName. Required.
- [<Drive>:][][ …] Specifies the location and file or files to search. At least one file name is required.
- /? Displays Help at the command prompt.
具体细节参考官网文档:
用法举例:
查找当前印象笔记的进程:
tasklist | findstr Evernote
查找当前VSCode的进程:
tasklist | findstr Code
注意,此处findstr中区分大小写
输出如下:
C:\Users\xxx>tasklist | findstr evernote C:\Users\xxx>tasklist | findstr Evernote Evernote.exe 12724 Console 1 211,120 K EvernoteSubprocess.exe 14788 Console 1 46,312 K EvernoteTray.exe 1176 Console 1 7,744 K EvernoteClipper.exe 2708 Console 1 10,300 K EvernoteSubprocess.exe 10512 Console 1 25,004 K EvernoteSubprocess.exe 3872 Console 1 25,072 K EvernoteSubprocess.exe 6476 Console 1 16,536 K EvernoteSubprocess.exe 5992 Console 1 16,528 K EvernoteSubprocess.exe 12696 Console 1 21,072 K EvernoteSubprocess.exe 13676 Console 1 25,664 K EvernoteSubprocess.exe 25652 Console 1 73,936 K EvernoteSubprocess.exe 24376 Console 1 66,552 K C:\Users\xxx>tasklist | findstr code C:\Users\xxx>tasklist | findstr Code Code.exe 24492 Console 1 88,280 K Code.exe 23516 Console 1 111,876 K Code.exe 14972 Console 1 156,988 K CodeHelper.exe 23132 Console 1 11,236 K Code.exe 22488 Console 1 86,440 K Code.exe 25440 Console 1 15,752 K Code.exe 20072 Console 1 68,228 K Code.exe 24636 Console 1 36,020 K

不区分大小写可以加上 /i
C:\Users\xxx>tasklist | findstr /i qq QQProtect.exe 3680 Services 0 13,108 K QQBrowser.exe 9028 Console 1 64,944 K QQBrowser.exe 10000 Console 1 19,012 K QQBrowser.exe 13148 Console 1 157,156 K QQBrowser.exe 7196 Console 1 14,708 K ...

【后记】
此处简单试了试,发现:
findstr xxx
等价于
find "xxx"
举例:
C:\Users\xxx>ipconfig /all | find /i "ipv4" IPv4 地址 . . . . . . . . . . . . : 192.168.31.119(首选)

其中 find xxx,xxx是字符串,会报错
C:\Users\xxx>ipconfig /all | find /i ipv4 FIND: 参数格式不正确
因为此处ipv4不是文件,只是普通字符串。
转载请注明:在路上 » 【已解决】 windows中类似于grep的命令