Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

awk grep question

  • 29-01-2009 04: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, Registered Users 2 Posts: 6,655 ✭✭✭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