You get a bonus - 1 coin for daily activity. Now you have 1 coin

Reverse GREP: removing lines that contain specific text

Practice



So, we all know the GREP utility. In normal use, it outputs only the lines from a file or input stream that contain the specified set of characters.

What we want is the opposite - to output all the lines except those that contain a certain set of characters.


Let's take this file test.txt as an example:
This is just a test
Another text
Third line
This is another line
Maximum text

Normal use of GREP - for example, to output only the lines containing "text":
$ cat test.txt | grep "text"
Another text
Maximum text

Now GREP in reverse, i.e. output all the lines except those containing "text":
$ cat test.txt | grep -v "text"
This is just a test
Third line
This is another line

Notice the "-v" flag? That's the whole trick right there ;)

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "LINUX operating system"

Terms: LINUX operating system