I have a configuration file which is a simple text. I want to list some configuration line but except some sitring. How can I use Linux grep to exclude and search for given strings? Thanks in advance for your help!
Have you checked MAN page for grep? there is option for this.
The lazy man way;
cat file.txt | grep "match this" | grep -v "not this"
I used to have a sticky note with a drawing of a cat that said "gratuitous use of cat award" one of our devs gave me. It disappeared when we moved.
-Otanx
I think egrep does it?
When I want to view a LONG config file that has like 10 lines of config and the rest are comments, I use this (which I stole from someone else)
egrep -v "\#|^$" someconfig.conf
Dont forget you can use regex as well. And dont foget to check the man pages! Usually they have examples there and if you were to do a linux exam this is all that you're allowed to check. So get used to it :)
man grep
man egrep
There are different ways to exclude and grep given a text file or input stream. I generally prefer the most basic one where use two grep where the first one is for exclude with -v option and pipe to second one where I grep for my string. grep -v 'able' config.txt | grep 'system' For more information look https://www.yjastar.com/ku/introduction-to-linux-grep-command-with-examples/