Find the answer to your Linux question:
Results 1 to 5 of 5
Quickest command to parse the IP address from a Received: header? Surely there's a really obfuscated way to do this using sed, I bet. For the uninitiated, the Received: syntax... ...
  1. #1
    Banned
    Join Date
    Dec 2002
    Location
    Texas
    Posts
    242

    Grab IP address from Received: header

    Quickest command to parse the IP address from a Received: header?
    Surely there's a really obfuscated way to do this using sed, I bet.

    For the uninitiated, the Received: syntax...

    Received: from FQDN (FQDN [10.20.30.40]) by FQDN blah, blah...

    (As some might imagine, I'm working on tweaking Procmail recipes.)

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Going strictly on the info you've provided, you could use:
    Code:
    [mrbig ~]$ echo 'Received: from FQDN (FQDN [10.20.30.40]) by FQDN blah, blah...' | sed -e 's/.*\[//' -e 's/\].*//'
    10.20.30.40

  3. #3
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    awk  '/Received/{gsub(/\[|\]|\)/,"",$5);print $5}' file

  4. #4
    Just Joined!
    Join Date
    Aug 2007
    Posts
    37
    Code:
    while read y; do z=${y%]*}; echo ${z#*[}; done <file

  5. #5
    Banned
    Join Date
    Dec 2002
    Location
    Texas
    Posts
    242
    Great info, thanks folks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...