LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 09: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, 10:31 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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, 10: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, 10:40 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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, 10: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, 02: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, 03:08 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

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


Reply



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 11:49 AM
Starting an xterm window that is "always on top" on command line azilkie Fedora 1 10-07-2005 09:17 PM
Error in man command "sh: line 1: /usr/bin/gtbl: No such file or directory" MinA Slackware 1 09-06-2004 06:36 PM
lrz won't send files, command line "gummed up" odat Linux - Software 0 05-23-2004 04:35 PM
When switched to command line, repeats "sr0: CD-ROM device not ready" over and over paradoxdruid Linux - General 7 10-21-2003 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:19 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
Open Source Consulting | Domain Registration