Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

awk grep question

Options
  • 29-01-2009 4:05pm
    #1
    Closed Accounts Posts: 667 ✭✭✭


    Hi Guys,

    Probably easy for soemone in here i wish to grab from below

    Jan 29 11:03:27 hostname postfix/smtp[27579]: [ID 197553 mail.info] 67F1623945F: to=<xxx@xxx.com>, relay=none, delay=3, status=bounced (Host or domain name not found. Name service error for name=xxx.com type=A: Host not found)

    fields 1, 2, 3, 10 and then 13 onwards as one chunk,

    eg

    Jan,29,11:03:27,to=<xxx@xxx.com>,status=bounced (Host or domain name not found. Name service error for name=xxx.com type=A: Host not found)

    I know i can awk out the first few with space delinmiter and print position, but the whole lot after the first comma ?

    Thanks

    Loz


Comments

  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    For the last bit, try a for loop:
    for (i=13; i<NF; i++) printf "%s", $i","; i++; printf "%s", $i"\n"
    


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    cut seems to work.
    cut -d ' ' -f 1,2,3,10,13- the-file.txt
    
    This says to use space as delimiter and return fields 1, 2, 3, 10 and then 13 on.
    Returns:
    Jan 29 11:03:27 to=<xxx@xxx.com>, status=bounced (Host or domain name not found.
     Name service error for name=xxx.com type=A: Host not found)
    


Advertisement