- Find all lines referencing the supreme court.
egrep -n "[Ss]upreme court" sample.txt
- Find all lines containing references to names. A reference begins with
a "Mr.", "Mrs.", "Ms.", or "Dr.", followed by a space, followed by a word.
egrep -n "(Mr\.|Mrs\.|Ms\.|Dr\.) [A-Za-z]+" sample.txt
- Find all lines containing references to names at the beginning of the line.
egrep -n "^(Mr\.|Mrs\.|Ms\.|Dr\.) [A-Za-z]+" sample.txt
- Find all lines containing references to real people. A "real people" name
begins with a "Mr.", "Mrs.", "Ms.", or "Dr.", followed by a space, followed
by a first name, a mandatory space, an optional middle initial (in
which case it will be followed by a period and a
space, i.e., ". "), and a last name.
egrep -n "(Mr\.|Mrs\.|Ms\.|Dr\.) [A-Za-z]+ ([A-Za-z]\. )?[A-Za-z]+" sample.txt
- Same thing, but search through all of the files in the current directory:
egrep -n "(Mr\.|Mrs\.|Ms\.|Dr\.) [A-Za-z]+ ([A-Za-z]\. )?[A-Za-z]+" ./*
- Recursive: use -R
- Find all lines containing social security
numbers.
egrep -n "[0-9]{3}-[0-9]{2}-[0-9]{4}" sample.txt