Command Line Examples: grep
From PHYSpedia
The grep command can be used to
- find files that contain a specific string of text
- "filter" text in a pipeline to only lines matching (or only lines not matching) a specific string of text
To search a single file for the string "password"
grep "password" file.txt
This will print a list of lines that contain the word password.
To search all files ending in .txt for the string "password"
grep "password" *.txt
This will print a list of lines that contain the word "password", but it will also show the file name that the line was found in.