Find the answer to your Linux question:
Results 1 to 5 of 5
Hi everyone, I'm trying to extract the domain name from an SMTP log for bad domains... All the @ symbols are messing up anything I try. File sample (domains edited): ...
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Posts
    2

    need help using grep / sed / awk to extract domain

    Hi everyone,

    I'm trying to extract the domain name from an SMTP log for bad domains...

    All the @ symbols are messing up anything I try.

    File sample (domains edited):
    @blah.com@0@MailGroup@rr7@21@0@0.00@@421
    @blah2.com@0@MailGroup@rr10@21@0@0.00@@421
    @blah3.net@0@MailGroup@rr2@21@0@9.00@@421
    @blah4.com@0@MailGroup@rr8@21@0@5.00@@421
    @blah5.com@0@MailGroup@rr12@21@0@11.00@@421
    @blah6.com@0@MailGroup@rr10@21@0@11.00@@421

    My last thought was to try pulling based on the .com/.net/.cc/.biz/etc but I can only get it to return the last 4 characters...

    Thanks for the help

  2. #2
    Just Joined!
    Join Date
    Jun 2008
    Posts
    10
    Well, this isn't sed or awk, but would the Cut command work for you?

    Code:
    cut -d "@" -f2 smptlogfile
    Generates:

    Code:
    blah.com
    blah2.com
    blah3.net
    blah4.com
    blah5.com
    blah6.com

  3. #3
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Try awk
    awk -F '@' '{print $2}' smptlogfile

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    if you have PHP
    Code:
    <?php
    $filename="file";
    if ( $handle = fopen($filename,"r") ){
     while( ( $data = fgetcsv($handle,0,"@")) !==FALSE ){
        echo "domain:$data[1]\n";
     }
    }
    fclose($handle);
    ?>

  5. #5
    Just Joined!
    Join Date
    Sep 2008
    Posts
    2
    Thanks ghostdog, secondmouse, and thinkwell.

    All 3 work perfectly.

Posting Permissions

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