The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating searches? amatuer_lee_3 Shell Programming and Scripting 2 05-12-2008 10:04 PM
grep multiple lines cdunavent Shell Programming and Scripting 27 03-27-2005 04:23 AM
grep - multiple positions nelson553011 AIX 3 11-16-2004 05:51 AM
New Tool Searches and Replaces SCO Code Neo News, Links, Events and Announcements 3 08-11-2003 09:37 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-14-2002
Registered User
 

Join Date: Feb 2002
Posts: 6
Stumble this Post!
grep: do multiple searches?

I want to search the file /etc/passwd for all lines containing 'csh' but exlude all those lines that have '/usr' in them and dump the results into the file result.

IMPORTANT: I need to do this in one command line.

The following does not work:

grep -v \(\/usr\) \(csh\) /etc/passwd > result

What is the basic thing that I am doing incorrectly here?

do I need do first search for all instances of 'csh' and then direct this into another grep for exclude all instances of '/usr' ??

grep -v '/usr' /etc/passwd | grep csh > result


regards and thanks,

Steve
Forum Sponsor
  #2 (permalink)  
Old 03-14-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Stumble this Post!
Why does this have to be on one command line? This sounds like a homework exercise - and that is not what this forum is for.......(just so you know).

The suggestion you made will work.....have you tried it?

grep -v '/usr' /etc/passwd | grep csh > result
__________________
Pete
  #3 (permalink)  
Old 03-14-2002
Cameron's Avatar
Registered User
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 486
Stumble this Post!
It's a homework question...
I thought I'd responded to a similar question a little while ago, see here .
  #4 (permalink)  
Old 03-14-2002
Registered User
 

Join Date: Feb 2002
Posts: 6
Stumble this Post!
yeah, I did figure this out on my own... that is why I put in the correct answer when I submitted the question.

I wasn't clear as to my real question or state of confusion...

I was struck by how simplistic these commands strings must be, and thought I was missing something.

When I tried to figure out the answer I just thought that there might be a way to put multiple arguments in one grep command instead passing the output onto another grep command.

Many years ago I did BLISS programming and I just have a lot of cobwebs stuck in my brain!
  #5 (permalink)  
Old 03-14-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Stumble this Post!
Well you could always write a new grep command..... that does what I suggested does...

new-grep /usr csh > result.

Some more homework!
__________________
Pete
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0