LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-09-2004, 10:49 AM   #1
podollb
Member
 
Registered: Oct 2003
Location: Grand Forks, ND
Distribution: Suse/Slackware/RH
Posts: 161

Rep: Reputation: 30
grep (not)


Is there a way to grep all lines that do NOT have somethign in them?

So if I had lines:

#Hi my name is
Blah Blah
#ok thanks

And I want to grep the file to only display all lines that don't have a # in them is that possible? And if so what is the command to do it?
 
Old 03-09-2004, 11:02 AM   #2
Rounan
Member
 
Registered: Jun 2003
Location: Ontario
Distribution: Ubuntu, Gentoo, Debian
Posts: 416

Rep: Reputation: 30
From man grep:

-v, --invert-match
Invert the sense of matching, to select non-matching lines.

so, to find lines that do NOT contain "foo":
grep -v foo

--Rounan

---------------------------------------------------
If you have a question, please check these in this order:

man and info pages for relevant commands
documentation that came with the program
tldp.org for a relevant HOWTO
Google and LinuxQuestions forum searches
THEN post a question if you can't find the answer.
-------------------------------------------------------
 
Old 03-09-2004, 11:03 AM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Here's an example. You need to escape the # because it's a special character.

cat test.txt | grep -v "#"
 
Old 03-09-2004, 11:05 AM   #4
bnice
Member
 
Registered: Feb 2004
Location: Sacramento, CA
Distribution: Slack 9.1, slackware-current
Posts: 284

Rep: Reputation: 30
Quote:
Originally posted by Rounan
From man grep:

-v, --invert-match
Invert the sense of matching, to select non-matching lines.

so, to find lines that do NOT contain "foo":
grep -v foo

--Rounan

note that # is a special character & needs to be escaped. <edit> or quoted.

Code:
grep -v \#  filename

Last edited by bnice; 03-09-2004 at 11:07 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
help on grep!!!! sanjith11 Programming 5 01-20-2005 05:43 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 01:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration