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!<\/p>","upvoteCount":10,"answerCount":7,"datePublished":"2019-04-03T07:26:11.000Z","author":{"@type":"Person","name":"spiceuser-6vumi","url":"https://community.spiceworks.com/u/spiceuser-6vumi"},"suggestedAnswer":[{"@type":"Answer","text":"
Advertisement
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!<\/p>","upvoteCount":10,"datePublished":"2019-04-03T07:26:11.000Z","url":"https://community.spiceworks.com/t/exclude-unwanted-string-from-linux-grep/705532/1","author":{"@type":"Person","name":"spiceuser-6vumi","url":"https://community.spiceworks.com/u/spiceuser-6vumi"}},{"@type":"Answer","text":"
Advertisement
Do you have an example of what you do and don’t want to see?<\/p>","upvoteCount":1,"datePublished":"2019-04-03T08:01:23.000Z","url":"https://community.spiceworks.com/t/exclude-unwanted-string-from-linux-grep/705532/2","author":{"@type":"Person","name":"Gary-D-Williams","url":"https://community.spiceworks.com/u/Gary-D-Williams"}},{"@type":"Answer","text":"
“grep” returns lines, based on a string found, (or not found if you invert with \" -v \").<\/p>\n
AFAIK, you cannot return something other than a line, unless you just want a count of the lines, or maybe an exit status.<\/p>\n
You could try “awk” to print specific fields after testing the value.<\/p>","upvoteCount":4,"datePublished":"2019-04-03T08:44:43.000Z","url":"https://community.spiceworks.com/t/exclude-unwanted-string-from-linux-grep/705532/3","author":{"@type":"Person","name":"pigdog","url":"https://community.spiceworks.com/u/pigdog"}},{"@type":"Answer","text":"
If I want to return all lines that contain “good string” except for lines which also contain “bad string” then I just do a double grep like so:<\/p>\n
Using regex you might be able to combine those into one command but I’ve never spent the time to look into it.<\/p>","upvoteCount":4,"datePublished":"2019-04-03T11:03:26.000Z","url":"https://community.spiceworks.com/t/exclude-unwanted-string-from-linux-grep/705532/4","author":{"@type":"Person","name":"brentmhk","url":"https://community.spiceworks.com/u/brentmhk"}},{"@type":"Answer","text":"