On Fri, Aug 20, 2010 at 12:42 PM, Paul Schmehl <pschmehl_li...@tx.rr.com> wrote:
> I'm trying to figure out how to use awk to parse values from a string of
> unknown length and unknown fields using awk, from within a shell script, and
> write those values to a file in a certain order.
>
> Here's a typical string that I want to parse:
>
> alert ip
> [50.0.0.0/8,100.0.0.0/6,104.0.0.0/5,112.0.0.0/6,173.0.0.0/8,174.0.0.0/7,176.0.0.0/5,184.0.0.0/6]
> any -> $HOME_NET any (msg:"ET POLICY Reserved IP Space Traffic - Bogon Nets
> 2"; classtype:bad-unknown;
> reference:url,www.cymru.com/Documents/bogon-list.html; threshold: type
> limit, track by_src, count 1, seconds 360; sid:2002750; rev:10;)

There's really no need for tr nor sed in awk since it has sub().

#!/usr/bin/awk -f

BEGIN {
        RS = ";"
}

$1 ~ /^sid:/ {
        sub(/^[[:space:]]*/,"")
        print
}

If you want to get other fields, making it into a function won't be
comfortable. You'd be better off using perl or lua in that case.

Andres
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to