LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-01-2005, 10:40 PM   #1
Rotwang
Member
 
Registered: Jan 2004
Distribution: CentOS
Posts: 281

Rep: Reputation: 30
command for "strip out every line that doesn't contain xxxxx"


Ok, so I'm stringing together some line commands here. Is there a line command that will do the following:

Given some newline seperated data (such as ls -l ) that's piped in ( with | ), do the following:

Remove every line that does NOT contain "abcdefg" on it. Or even better, could it remove every line that does not contain a regexp like /a*bcd(e|g)/;
 
Old 08-01-2005, 11:31 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Yes. It's called grep.

Specifically, it PRINTS every line that DOES contain the expression. Use 'egrep' for the more extended regexps, like above.
 
Old 08-01-2005, 11:36 PM   #3
Shade
Senior Member
 
Registered: Mar 2003
Location: Burke, VA
Distribution: RHEL, Slackware, Ubuntu, Fedora
Posts: 1,418
Blog Entries: 1

Rep: Reputation: 46
the -v option to grep will remove any line that contains the following exp. such as:

Code:
ls -l |grep -v whatever
Every line which does *not* include 'whatever' will be returned.

--Shade
 
Old 08-01-2005, 11:40 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
I think the OP wanted to remove those that do NOT contain the expression. Which would be equivalent to printing those that DO contain the expression. Hence, no -v.
 
Old 08-01-2005, 11:42 PM   #5
Shade
Senior Member
 
Registered: Mar 2003
Location: Burke, VA
Distribution: RHEL, Slackware, Ubuntu, Fedora
Posts: 1,418
Blog Entries: 1

Rep: Reputation: 46
Wow. I think you're right. These double negatives confuse me

--Shade
 
Old 08-02-2005, 03:49 PM   #6
Rotwang
Member
 
Registered: Jan 2004
Distribution: CentOS
Posts: 281

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by Matir
Yes. It's called grep.

Specifically, it PRINTS every line that DOES contain the expression. Use 'egrep' for the more extended regexps, like above.
Thanks. Duuh. I'm embarassed. (I think my double negatives confused me too.)
 
Old 08-02-2005, 04:08 PM   #7
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
No problem. Don't be embarassed, I've asked plenty of obvious questions.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cdrecord command-line parentheses "(" ")" coolingtower Linux - Software 1 10-28-2005 12:49 PM
Starting an xterm window that is "always on top" on command line azilkie Fedora 1 10-07-2005 10:17 PM
Error in man command "sh: line 1: /usr/bin/gtbl: No such file or directory" MinA Slackware 1 09-06-2004 07:36 PM
lrz won't send files, command line "gummed up" odat Linux - Software 0 05-23-2004 05:35 PM
When switched to command line, repeats "sr0: CD-ROM device not ready" over and over paradoxdruid Linux - General 7 10-21-2003 06:44 PM


All times are GMT -5. The time now is 12:27 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration