Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jul 2003 11:04:54 -0500
From:      D J Hawkey Jr <hawkeyd@visi.com>
To:        Rob <listone@deathbeforedecaf.net>
Cc:        questions at FreeBSD <freebsd-questions@freebsd.org>
Subject:   Re: sed(1) regular expression gurus
Message-ID:  <20030714160454.GA28042@sheol.localdomain>
In-Reply-To: <00b001c34a1b$4ad17800$a4b826cb@goo>
References:  <20030714140816.GA27439@sheol.localdomain> <00b001c34a1b$4ad17800$a4b826cb@goo>

next in thread | previous in thread | raw e-mail | index | archive | help
On Jul 15, at 12:49 AM, Rob wrote:
> 
> awk --posix -F'[^0-9A-Za-z.]+' '
>   $1 ~ /by/ { result = $2
>     for (i=3; i<=NF; i++) {
>       if ($i ~ /^([0-9]+\.){3}[0-9]+$/) {
>         result = result " " $i
>       }
>     }
>   print result
>   }'
> 
> There may be 'neater' ways of doing it, but it's the most concise
> example I could come up with.

This is better than anything I've dreamed up with sed or awk, and is
really close, but it fails on this:

  by nospam.mc.mpls.visi.com (8.11.6/8.11.6.2) with ESMTP id 3A4E07B03

The parenthetical is a [hacked] sendmail version. I don't see how the
script fails, though, as you do test for a full/complete "dotted quad",
and even test for a BOL and EOL on either side it. The "8.11.6" shouldn't
match. I changed the '+'es to "{1,3}"s for even better precision in the
"if (...)", but it didn't make any difference (nor should it have).

BTW, why the "one or more" flag in the FS assignment?

> You need to include the --posix option to get the '{3}' notation to work
> (peculiar to GNU awk).

Kinda throws portability out the window, but I'll settle for it.

Dave

-- 
  ______________________                         ______________________
  \__________________   \    D. J. HAWKEY JR.   /   __________________/
     \________________/\     hawkeyd@visi.com    /\________________/
                      http://www.visi.com/~hawkeyd/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030714160454.GA28042>