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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Grepping out one value in multiple line file

  • 04-11-2008 12:09pm
    #1
    Registered Users, Registered Users 2 Posts: 5,659 ✭✭✭


    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