Home > Enterprise >  How to exctract a string from terminal in Linux?
How to exctract a string from terminal in Linux?

Time:11-20

When I execute a script, I obtain the following text into terminal:

GN status:
MAC addr: 10:98:C3:73:64:CD
Lastest Update Time: 2021-11-18 10:26:18(GMT 0)
--- Media Layer---
  TX Packet:
    Total: 68360
    Success: 68360
    Failure: 0
  RX Packet:
    Total: 751063
    Success: 751063
    Dropped: 0
    CRC Error: 313

All I want to do is to obtain the value 751063:

 RX Packet:
        Total: 751063

How can I show only this number into the terminal and erase all the other words?

CodePudding user response:

Have you tried anything on your own?

this will work:

your_command|grep 'RX Packet:' -A1|grep Total|head -1|awk '{print $2}'
  • Related