How Can I Filter Console Output Using Findstr Command?

There is a command named “findstr”, which you can use by combining with the ‘|’ (pipe) symbol to extract or filter only the portion of the console command output, based on the included terms and excluded terms, that you pass as an argument.

The command file is an executable named “findstr.exe” and can be located at the system directory (generally, at “C:\Windows\System32” folder).

When you want to find and display only the records that includes a specific term or the terms, you have to pass the following command switch parameters: “/r /c”. To pass a single term, use /c:”TERM”. To pass the multiple terms, use /c:”TERM1” /c:”TERM2” … /c:”TERMn” … and so on. The parameter “/r” uses the search strings/terms as the regular expressions, whereas “/c” follows the string/term and uses it as a literal search string.

For example, the following command filters out only the command output of “dir” that has a term “Music”:

dir | C:\Windows\System32\findstr.exe /r /c:”Music”

The command filter, given below, is the command output of “dir”, that has either one of the following terms “Music”, “Documents” or “Down”:

dir | C:\Windows\System32\findstr.exe /r /c:”Music” /c:”Documents” /c:”Down”

If you want to exclude a line that has a specific string/term, you can use the switch “/v” followed by the words under “/c”, as discussed above. To exclude a single term, use /c:”TERM”. To exclude the multiple terms, use /c:”TERM1” /c:”TERM2” … /c:”TERMn” … and so on.

For an example, the command filters out the command output of “dir” and prints only those lines, which don’t have the term “Music” or “Documents”:

dir | C:\Windows\System32\findstr.exe /r /v /c:”Music” /c:”Documents”

I hope that the point is clear to you now and you will be able to filter out a specific console command output, based on a term to include or exclude from the result.
Ebook Download
View all
Learn
View all