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