Linux Exclude unwanted string from Linux grep

Gabriel Turqos

New Member
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!
 


livix07

Well-Known Member
I think you have more chances to find the answer on Stackoverflow.
 


Neemobeer

Windows Forum Team
Staff member
Specifically using grep you'd need to pipe one grep to another such as say you want to find occurrences of 'car' but not 'racecar'

grep 'car' /home/user/somefile.txt | grep -v 'racecar'

It would be a shorter command if you used egrep but you'd need to understand regex expressions to make correctly.
 


samuel tarcin

New Member
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 Introduction to Linux Grep Command With Examples - POFTUT
 


This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.
Top