Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-02-2006, 06:38 PM
|
#1
|
LQ Newbie
Registered: May 2006
Posts: 3
Rep:
|
awk print lines that doesn't have a pattern
Hi,
I'm looking for a way to print out lines that do not have the words Mozilla, Opera or JanusUtils.
So far I can print the lines that have Mozilla, but I am unsure how to do this for multiple words and to not print them instead of printing them.
Code:
awk '/Mozilla/ {print}'
Any help is appreciated. Thanks,
Huy
|
|
|
05-02-2006, 08:39 PM
|
#2
|
Member
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892
Rep:
|
If you're not tied to using Awk, GNU Grep can do it:
Code:
grep -Ev 'Mozilla|Opera|JanusUtils'
The -v option means show lines that don't match, -E means use extended regular expressions (seems to be required to use the pipe [which means "or"] correctly).
|
|
|
05-03-2006, 02:29 PM
|
#3
|
LQ Newbie
Registered: May 2006
Posts: 3
Original Poster
Rep:
|
Quote:
Originally Posted by taylor_venable
If you're not tied to using Awk, GNU Grep can do it:
Code:
grep -Ev 'Mozilla|Opera|JanusUtils'
The -v option means show lines that don't match, -E means use extended regular expressions (seems to be required to use the pipe [which means "or"] correctly).
|
That works, but unfortunately I am tied to using Awk. From your example, I was able to expand to this now
Code:
awk '/Mozilla|Opera|JanusUtils/ {printf "%s\t%s\t%s\n",$12,$4,$1 }'
There must be a way to not print those finds. =/
|
|
|
05-03-2006, 08:58 PM
|
#4
|
Member
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892
Rep:
|
OK, in that case, you can use an "if" statement. This file will check for (the lack of) a match on variable $1:
Code:
{
if ( $1 !~ /Mozilla|Opera|JanusUtils/ ) {
print $1;
}
}
It's a little less flexible than being able to match the entire line, but if what you're looking for can only occur in one column, it should work. Otherwise... I'd have to dig through my Awk book some more.
|
|
|
05-04-2006, 01:59 AM
|
#5
|
LQ Newbie
Registered: May 2006
Posts: 3
Original Poster
Rep:
|
Thanks that worked and made me think of another possible solution.
Code:
awk '!/Mozilla|Opera|JanusUtils/ {printf "%s\t%s\t%s\n",$12,$4,$1 }'
I tried adding the ! and it worked!! I should've thought of that earlier =P Thanks for the inspiration!
|
|
|
05-04-2006, 11:08 AM
|
#6
|
Member
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892
Rep:
|
Cool; I had no idea that feature existed. I guess it just shows that the best way to learn around Unix is through experimentation.
|
|
|
All times are GMT -5. The time now is 05:27 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|