fgrep command in Linux

“fgrep” stands for “Fixed-String Global Regular Expressions”. It looks for lines that match a pattern in the files given by the File parameter or in the standard input by default. If you put more than one file in the File parameter, the fgrep command shows the file that has the matched line. The fgrep command uses an algorithm that is quick and small, also search for strings that have a lot of metacharacters for regular expressions, such as $, *, [, |, (, ), and so on.

Command

$ fgrep [options] [-e pattern_list] pattern [file]

Options

Here are details about some options.

OptionDetails
-iIgnore case differences in patterns and input data so that characters that only differ in case will match.
-fObtain patterns from File, one per line.
-e PatternTells you about a pattern. It works like a simple pattern, but it is useful when the pattern starts with a minus sign (-).
-hDisplay the matched lines, but do not display the filenames.
-cPrint out the number of matching lines in each file.
-lOnly shows a list of filenames.
-nShow the lines that match and their line numbers.
-vThis makes all the lines that do not fit the pattern print out.
-wSelect  only  those  lines  containing  matches  that form whole words.
-xDisplays lines that exactly match the pattern without any extra characters.
-RRead  all  files  under each directory, recursively.

Examples

  • Now, let us see some examples.
fgrep -i linux linux_introduction.txt
fgrep -c Linux linux_introduction.txt
fgrep -w Linux linux_introduction.txt
fgrep -n Linux linux_introduction.txt
fgrep -l Linux *
fgrep -x Ubuntu linux_distributions.txt

Feedback

Do you want to provide us with feedback? Provide us with feedback directly at info@elearnbee.com.

Share us:

AD BLOCK 1