Taking advantage of the grep command’s many options

The grep command makes it easy to find strings in text files on Linux systems, but that’s just a start. It can be used to search through these files for multiple strings or regular expressions at the same time. It can also ignore case when needed, and it can count the lines in the resulting output for you. This post shows how to use grep in all these ways.

Basic grep

The simplest grep command looks like the one shown below. This “find string in file” command will show all the lines in the file that contain the string, even when that string is only part of a longer one.

$ grep word story
The wording suggests there was more to the story than anyone wanted to admit.
The sword had been left behind the shed. It was several days before it was

Finding multiple strings

There are a number of ways to search for a group of strings in a single command. In the command below, the ‘|’ character serves as an “or” function. The command will display any lines in the file that contain the word “xray”, the word “tape” or both.

To read this article in full, please click here

Source:: Network World – Linux