Computing.Net > Forums > Unix > grep for line with one word and not another?

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 for line with one word and not another?

Reply to Message Icon

Name: nghate
Date: July 10, 2009 at 11:38:25 Pacific
OS: unix
Subcategory: General
Comment:

I want to grep for lines containing one word but not another... can the following be combined into one grep?

grep -v "WORD2" file | grep "WORD1"



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: July 14, 2009 at 18:52:20 Pacific
Reply:

use awk

awk '/word2get/ && !/junk/' file 

GNU win32 packages | Gawk


0

Response Number 2
Name: nghate
Date: July 15, 2009 at 16:18:05 Pacific
Reply:

Thanks ghostdog... that works... :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: grep for line with one word and not another?

Searching for more then one word www.computing.net/answers/unix/searching-for-more-then-one-word/5027.html

How to compare form feed? www.computing.net/answers/unix/how-to-compare-form-feed/6817.html

Need help with a search and replace logi www.computing.net/answers/unix/need-help-with-a-search-and-replace-logi/3296.html