sed(1) regular expression gurus
D J Hawkey Jr
hawkeyd at visi.com
Mon Jul 14 11:01:53 PDT 2003
On Jul 14, at 11:04 AM, D J Hawkey Jr wrote:
>
> 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
> > }'
>
> 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
Another astute fellow offered this:
sed -E \
-e "s/by[[:space:]]+//" \
-e "s/\(\[?(([0-9]{1,3}\.){3}[0-9]{1,3})\]?\)/\1/" \
-e "s/[[:space:]]*(\(|id|via|with|E?SMTP|;).*//"
The idea being to pull anything that looks like an IP address out of
parentheses first (2nd command), then junk any other parenthetical
stuff with the other cruft on the line (3rd command).
I did learn a new "syntax" from your script, nonetheless. Thanks,
Dave
--
______________________ ______________________
\__________________ \ D. J. HAWKEY JR. / __________________/
\________________/\ hawkeyd at visi.com /\________________/
http://www.visi.com/~hawkeyd/
More information about the freebsd-questions
mailing list