Grep Command for Windows - Top 10 Example Usage of 'findstr' Command

'grep' command for Windows - findstr is the command you can use on Windows-based OS which helps in searches for patterns of text in files (like grep). In this article, we will cover the Top 10 Example Usage of 'findstr' command.

(1) To identify .exe files

dir | findstr .exe

(2) To search for "fox and lion" in file test.txt

findstr /c:"fox and lion" test.txt

(3) Command used to display available options at the command prompt

findstr /?

(4) Search string "allabouttesting" in a file test.txt

findstr allabouttesting test.txt

(5) Print occurrence of string "allabouttesting" in a file test.txt

findstr -N allabouttesting test.txt

(6) Ignores the case of the characters when searching for the string "udp"

netstat -an | findstr -i udp

(7)Print the line number of each line that matches "tcp"

netstat -an | findstr -i /n tcp

(8) Gets search strings from the file "stringlist.txt. Gets a file list from the file.txt

findstr /g:stringlist.txt /f:file.txt > output.txt

(9) To search for tcp or udp in file test.txt

findstr tcp udp test.txt

(10) Print only lines that don't contain a "tcp"

netstat -an | findstr -i /v tcp

Conclusion

In this article, we have covered the basic usage of findstr command. You can use it more creatively by combining different options and use it like grep to identify the required information.

Subscribe us to receive more such articles updates in your email.

If you have any questions, feel free to ask in the comments section below. Nothing gives me greater joy than helping my readers!

Disclaimer: This tutorial is for educational purpose only. Individual is solely responsible for any illegal act.

You may also like...

Leave a Reply

Your email address will not be published.