grep command tips
Sometimes only specific lines of a file with certain text on it
need to be seen. The grep command
examines a file and only display lines that contain a certain
This example displays all the lines in the
required_packages.txt file which contain the string gcc. In this
usage, grep matches the string gcc in only its given lowercase
form. To search for a string without case sensitivity, add the -i
Occasionally, you may want to reverse this search and look for
lines which do not contain a given piece of text. In that case,
use the -v option for grep.
$ grep -v
-i rpm required_packages.txt
Refer to Note 880211.1
In this example, the two options -v and -i have been combined
to search without case sensitivity for lines that do not contain
the string rpm. When using multiple options, most Linux commands
will let you combine them after a single hyphen. Entering grep -i
-v is the same as grep -iv.
These are the most common ways file contents may be viewed. In
the next chapter, how to edit files with the popular, though often
maligned, vi editor will be shown.