General discussion

Locked

awk - help with "|" as "or" and syntax

By cpfeiffe ·
I have an awk statement on my log server that discards ignorable data and emails the rest once a day. The statement is

awk '! /\.debug\]/ && ! /\.info\]/ && ! ......

I want to combine the .debug] and .info] matches in one expression with or so I tried

awk '! /[\.debug\]|\.info\]]/ && ! ......

This doesn't seem to work. I was able to a simpler join as follows

&& ! /wally updater/ && ! /dilbert updater/ && ! ......

rewritten as

&& ! /[wally|dilbert] updater/ && ! ......

Any ideas why it isn't working with the first expression set?

This conversation is currently closed to new comments.

8 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Gary_W In reply to awk - help with "|" as "o ...

I'm a little rusty so bear with me...

You want all lines that don't contain ".debug]" or ".info]" right? What about this simple example:

awk '!/.debug]|.info]/ {print $0}' filename

Removing the bang ('!') prints all lines containing ".debug]" or ".info]"

This works on my machine anyway.

Gary

Collapse -

by Gary_W In reply to

Hmmm. I am using a Sun box running SunOS 5.8. I tested with the korn shell.

Try again but use nawk. It seems to give a little more info in it's error messages.

Mine doesn't work if I escape the '.' and ']'.

Interesting.

Collapse -

by Gary_W In reply to

I lied! This works too:

awk '!/\.info\]|\.debug\]/{print $0}' x

Collapse -

by Gary_W In reply to

Look close at your example:
awk '! /[\.debug\]|\.info\]]/ && ! ......
^ ^
| |
Try removing these square brackets.

Good thing it's a slow day today.
Gary

Collapse -

by Gary_W In reply to

ARGH My little arrows don't line up. Try removing the square brackets that surround the expression. I believe all you need to surround the expression are the '/'s.

Ok, back to work.

Collapse -

by cpfeiffe In reply to

Thanks. I've printed your answers. I don't know when I'll get back to this, but I'm sure its a syntax error and if nothing else its just nice to see what works in another environment. I can play with it from here.

Collapse -

by cpfeiffe In reply to awk - help with "|" as "o ...

Gary_W - how are you getting away with not escaping the . and ]? I did the exact same thing except that I did used a \ in front of the . and ] on both. I tried not escaping these and it didn't work either. What version of awk are you using and what OS are you on?

Collapse -

by cpfeiffe In reply to awk - help with "|" as "o ...

This question was closed by the author

Back to Linux Forum
8 total posts (Page 1 of 1)  

Related Discussions

Related Forums