Computing.Net > Forums > Unix > grep command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

grep command

Reply to Message Icon

Name: the_apostle21
Date: March 3, 2004 at 16:59:44 Pacific
OS: Digital UNIX
CPU/Ram: Digital
Comment:

I am only fairly new to unix, so i have a question about grep....

i use the grep command at work to search for particular records. i use the grep command as "grep <criteria> <filename>".

i know it is possible to search for two criterias in the one command, but am unsure how to do it. i need to know how to, for example, search for criteria A AND criteria B in the one file in the one one command.

can someone please explain to me how i can do this.

thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: aigles
Date: March 4, 2004 at 00:44:07 Pacific
Reply:

If you want to select records which satisfies the criteria A OR B :

grep 'criteria A|criteria B' input_file

If you want to select records which satisfies the criteria A AND B :

grep 'criteria A' input_file | grep 'criteria B'


Jean-Pierre.


0

Response Number 2
Name: Dlonra
Date: March 4, 2004 at 12:52:53 Pacific
Reply:

" If you want to select records which satisfies the criteria A OR B :
grep 'criteria A|criteria B' input_file "

No: grep -E or egrep 'criteria A|criteria B' input_file

"if you want to select records which satisfies the criteria A AND B :
grep 'criteria A' input_file | grep 'criteria B' "

No: grep 'criteria B' $(grep -l 'criteria A' input_file)



0

Response Number 3
Name: aigles
Date: March 4, 2004 at 23:01:59 Pacific
Reply:

No: grep -E or egrep 'criteria A|criteria B' input_file
That's right

No: grep 'criteria B' $(grep -l 'criteria A' input_file)
No, your command select records matching 'criteria B' from files which contains a record matching 'criteria B'.

Records matching 'criteria A' are not displayed.
Displayed records match 'criteria B', not criteria A AND B.


Jean-Pierre.



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: grep command

Help on grep command www.computing.net/answers/unix/help-on-grep-command/7376.html

can I use grep command?? www.computing.net/answers/unix/can-i-use-grep-command/7156.html

Using the grep command www.computing.net/answers/unix/using-the-grep-command/4811.html