Exclusive Grep
0 votos
November 7th, 2006 liewsheng Posted in Text Manipulation, grep | Hits: 6028 |
When you have ‘grep’ some keyword:
grep "keyword" filename
tons of lines and dozen of words you don’t want may show on the screen. What can you for this? Of cause is filter out the unwanted word ;p it is easy to ‘exclusive’ the unwanted keyword:
grep "keyword" filename | grep -v "non-keyword"
the ‘-v’ here will display those keyword which don’t match with “non-keyword”. For example, if you have a file, abc.txt, with this contents:
testing, 12345
#testing , this the wrong code
testing 3456
testing, 452345
testing, 652345
ates, 953645
btest 452345
#testing , this wrong code
#testing , this wrong code
#testing , this the wrong code
and you want to grep a “testing” keyword but not those staring with “#”:
grep testing abc.txt | grep -v #testing
and the result will be:
testing, 12345
testing 3456
testing, 452345
testing, 652345
Live Chat!









November 7th, 2006 at 10:40 pm
[...] Using the file form previous examples (Exclusive Grep), output of command below: [...]
November 7th, 2006 at 11:01 pm
[...] this will only display the line with matching word. Using the file contents in previous example, if this command enter: [...]
June 23rd, 2007 at 7:33 pm
hello,
please let me know that what we can search the any file through grep command using some keyword of that file.
Regards’
Manoj devrari
June 24th, 2007 at 2:29 pm
manoj,
You are asking to search for files, where you specified keywords as for file name?
use command find or locate instead, checkout the examples at here
August 16th, 2007 at 1:16 pm
How to search for existance of two keywords in a file. -either with AND or “OR”.
For example I want to search a line in a file containing both the keywords or maybe I want to grep lines that doesnt contain either of the keywords
Thanks in advance
Amit
August 17th, 2007 at 1:23 am
Amit, refers to examples at
http://linux.byexamples.com/archives/290/grep-multiple-keywords-and-not-or/
use -v for inverse-match.
August 20th, 2007 at 10:28 pm
please let me know how to search for a keyword in a folder