Difference between revisions of "Command Line Examples: grep"

From PHYSpedia
Jump to: navigation, search
(Created page with "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 s…")
 
(No difference)

Latest revision as of 10:16, 7 February 2013

The grep command can be used to

  1. find files that contain a specific string of text
  2. "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.