Re: Any awk gurus on the list?



On Fri, Aug 20, 2010 at 12:42 PM, Paul Schmehl <pschmehl_lists@xxxxxxxxx> 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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Any awk gurus on the list?
    ... unknown length and unknown fields using awk, from within a shell script, and ... my understanding of awk. ... to use an associative array, ... For simple record-by-record processing scalar vars suffice. ...
    (freebsd-questions)
  • Re: Any awk gurus on the list?
    ... unknown length and unknown fields using awk, from within a shell script, and ... improve my understanding of awk. ... if then ditto into an element named ref ...
    (freebsd-questions)
  • Any awk gurus on the list?
    ... 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. ...
    (freebsd-questions)
  • Re: piped to awk: how to print vars outside of line-in loop
    ... I have been tinkering with a shell script that takes the output from a ... program and pipes it to awk to extract certain items and format them ... print "Encoder is: " Encoder ... print "Container is:" Container ...
    (comp.unix.shell)
  • Re: Multi line match and uniq.
    ... >(Generated by a java process sending the error to Stnd error and std ... And a shell script sending both to a file.) ... facility 'awk' has for dealing with NEWLINE delimited records (setting ...
    (comp.unix.shell)