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.

Grepping out one value in multiple line file

  • 04-11-2008 01:09PM
    #1
    Registered Users, Registered Users 2 Posts: 5,753 ✭✭✭


    Hi all

    Looking to just take out the value below out of this file. Do you have unix command that can do this handy?



    SERVER (IMH_FMAI_server)
    Identity start #rcv #snd top BS top Q curr Q
    ======== ===== ==== ==== ====== ===== ======
    159.107.173.173.49912 20081104100014 315824 342893 1664 23 23


    CLIENT COUNTERS
    Identity start #rcv #snd top BS curr BS top Q curr Q
    ======== ===== ==== ==== ====== ======= ===== ======
    159.107.173.173.27847 20081104100014 2 6 116 116 -1 0
    159.107.173.173.27864 20081104100014 1 0 116 116 -1 0
    159.107.173.173.35480 20081104100014 1 0 460 500 -1 0
    159.107.173.173.35483 20081104100014 1 0 460 500 -1 0
    159.107.173.173.35486 20081104100014 1 0 460 500 -1 0
    159.107.173.173.35490 20081104100014 2 0 484 0 -1 0
    159.107.173.173.35491 20081104100014 1 0 468 508 -1 0
    159.107.173.173.35495 20081104100014 1 0 472 512 -1 0
    159.107.173.173.35498 20081104100014 1 0 460 500 -1 0
    159.107.173.173.35501 20081104100014 1 0 460 500 -1 0
    159.107.173.173.46775 20081104100014 6 4 144 112 -1 0
    159.107.173.173.35543 20081104100014 1 0 464 504 -1 0
    159.107.173.173.35546 20081104100014 1 0 460 500 -1 0
    159.107.173.173.46968 20081104100014 9794 3 1348 1196 -1 0
    159.107.173.173.35630 20081104100014 203412 0 1024 0 -1 0
    159.107.173.173.35526 20081104100014 1 0 460 500 -1 0
    159.107.173.173.17330 20081104100014 31496 314350 1076 0 -1 23

    SERVER (IMH_alarm_server)
    Identity start #rcv #snd top BS top Q curr Q
    ======== ===== ==== ==== ====== ===== ======
    159.107.173.173.49911 20081104100017 315346 173108 1732 43325 0


    CLIENT COUNTERS
    Identity start #rcv #snd top BS curr BS top Q curr Q
    ======== ===== ==== ==== ====== ======= ===== ======
    159.107.173.173.27843 20081104100017 2 0 68 68 -1 0
    159.107.173.173.34917 20081104100017 12 0 348 68 -1 0
    159.107.173.173.46772 20081104100017 1 5939 72 72 -1 0
    159.107.173.173.17329 20081104100017 315314 0 1732 828 -1 0
    FMAI*****


Comments

  • Registered Users, Registered Users 2 Posts: 1,193 ✭✭✭liamo


    Assuming that
    1. The value you want will always be on the 4th line
    2. The fields are always delimited with a space
    3. The value you want will always be in the 7th position

    this should do the trick:

    head -n4 myfile | tail -n1 | cut -d" " -f 7
    (where "myfile" is the name of your file)

    Regards,

    Liam


  • Registered Users, Registered Users 2 Posts: 868 ✭✭✭brianmc


    Hi all

    Looking to just take out the value below out of this file. Do you have unix command that can do this handy?



    SERVER (IMH_FMAI_server)
    Identity start #rcv #snd top BS top Q curr Q
    ======== ===== ==== ==== ====== ===== ======
    159.107.173.173.49912 20081104100014 315824 342893 1664 23 23

    Alternately if it's always the last value on the 3rd line after the first "SERVER" line then try a bit of awk...
    
    awk 'BEGIN { LNO = 0 } /^SERVER/ { if (LNO == 0) { LNO = NR + 3 } } NR == LNO { print $NF; exit }' inputfile.txt
    

    ^^^ That's not tested.


Advertisement