Findstr is the Windows alternative to GREP, which runs on the Unix operating system. Findstr searches files with regular expressions and seems useful for string matching within files and directories. It is one of over 280 command prompt commands. Here’s the official Windows Documentation and some Linux vs. Windows Examples.
Update: Windows announced that Grep and several other Unix command line tools will be added to Windows 10. This is a new alternative to findstr.
This findstr command returns all lines containing an ‘@’ in a text file.
findstr @ test.txt
I was happy to see Findstr’s convenient help menu:
Regular expressions are so powerful. It’s nice to have this utility within the command prompt. I am hoping to get to know some of the other 280 command prompt commands.
I’ve previously explored regex with Python. This Python regex example finds all words in a text file containing ‘@’ symbols:
import re """ regex email search - Python Marketer https://pythonmarketer.wordpress.com/2018/07/15/findstr-aka-grep-for-windows/ """ with open('test.txt', 'r') as fhand: string = fhand.read() # this regex returns a python list of emails: emails = re.findall('(\S*@\S+)', string) print(emails)
For more command prompt nuggets, check out my more recent post: Exploring Windows Command Line Tools, Batch Files and Remote Desktop Connection.