Searching for Text Inside Files
The grep
command is the one to
remember.
Examples:
grep "Alexander Hamilton"
essay.txt
grep -l "Alexander Hamilton" *
egrep "^[0-9].*SOLD$" real_estate.txt
Tasks:
- What Mac GUI program does something
similar?
- What would be some advantages of
searching files using
grep
intead of the GUI?
Tips:
- Read the
man
page for grep
to learn
about its many options, for example the -i
option makes
the search case-insensitive.
- Combine
grep
with the find
command
(described later) to find a bunch of files and search them in one
command line.
List of Links:
- Steve Ramsay's Guide to Regular Expressions
- Learning to Use regular Expressions, from IBM