General discussion

  • Creator
    Topic
  • #2297664

    awk – help with “|” as “or” and syntax

    Locked

    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?

All Comments

  • Author
    Replies
    • #2670953

      Reply To: awk – help with “|” as “or” and syntax

      by gary_w ·

      In reply to awk – help with “|” as “or” and syntax

      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

      • #2670907

        Reply To: awk – help with “|” as “or” and syntax

        by gary_w ·

        In reply to Reply To: awk – help with “|” as “or” and syntax

        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.

      • #2670906

        Reply To: awk – help with “|” as “or” and syntax

        by gary_w ·

        In reply to Reply To: awk – help with “|” as “or” and syntax

        I lied! This works too:

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

      • #2670899

        Reply To: awk – help with “|” as “or” and syntax

        by gary_w ·

        In reply to Reply To: awk – help with “|” as “or” and syntax

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

        Good thing it’s a slow day today.
        Gary

      • #2670898

        Reply To: awk – help with “|” as “or” and syntax

        by gary_w ·

        In reply to Reply To: awk – help with “|” as “or” and syntax

        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.

      • #3369728

        Reply To: awk – help with “|” as “or” and syntax

        by cpfeiffe ·

        In reply to Reply To: awk – help with “|” as “or” and syntax

        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.

    • #2670918

      Reply To: awk – help with “|” as “or” and syntax

      by cpfeiffe ·

      In reply to awk – help with “|” as “or” and syntax

      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?

    • #3369727

      Reply To: awk – help with “|” as “or” and syntax

      by cpfeiffe ·

      In reply to awk – help with “|” as “or” and syntax

      This question was closed by the author

Viewing 2 reply threads