Remove lines from command output

I’m running below command; I need to store the command’s output in a file but without headers.

I tried – yarn top | tail -n +8 (as yarn top works like Linux top it refreshes in every 3 seconds and repeats output)

yarn top
YARN top - 00:47:26, up 24d, 2:49, 0 active users, queue(s): root
NodeManager(s): 7 total, 7 active, 0 unhealthy, 0 decommissioned, 0 lost, 0 rebooted
Queue(s) Applications: 8 running, 111 submitted, 15 pending, 111 completed, 5 killed, 5 failed
Queue(s) Mem(GB): 100 available, 20 allocated, 0 pending, 0 reserved
Queue(s) VCores: 200 available, 2 allocated, 0 pending, 0 reserved

                  APPLICATIONID USER             TYPE      QUEUE   #CONT  #RCONT  VCORES RVCORES     MEM    RMEM  VCORESECS    MEMSECS %PROGR       TIME NAME
application_1484661449412_1115434 papp     mapreduce    default       3       0       3       0     16G      0G         28        172   5.00   00:00:00 EdmHdpIf-SRI
application_1484661449412_1115420 papp     mapreduce    default       2       0       2       0     12G      0G         86        545  95.00   00:00:00 oozie:launch
application_1484661449412_1115433 eapp     mapreduce       eapp       2       0       2       0     12G      0G         23        160   5.00   00:00:00 oozie:launch
application_1484661449412_1115386 eapp     mapreduce       eapp       2       0       2       0     12G      0G        250       1524  95.00   00:00:02 oozie:launch

Expected output

application_1484661449412_1115434 papp     mapreduce    default       3       0       3       0     16G      0G         28        172   5.00   00:00:00 EdmHdpIf-SRI
application_1484661449412_1115420 papp     mapreduce    default       2       0       2       0     12G      0G         86        545  95.00   00:00:00 oozie:launch
application_1484661449412_1115433 eapp     mapreduce       eapp       2       0       2       0     12G      0G         23        160   5.00   00:00:00 oozie:launch
application_1484661449412_1115386 eapp     mapreduce       eapp       2       0       2       0     12G      0G        250       1524  95.00   00:00:02 oozie:launch

Answer

Using grep, works best in this case:

1) yarn top | grep -A20 APPLICATIONID

A – Print data after matching string

20 – number of lines to be printed after (A) matching string

[[email protected] sh]$ cat text1 
YARN top - 00:47:26, up 24d, 2:49, 0 active users, queue(s): root
NodeManager(s): 7 total, 7 active, 0 unhealthy, 0 decommissioned, 0 lost, 0 rebooted
Queue(s) Applications: 8 running, 111 submitted, 15 pending, 111 completed, 5 killed, 5 failed
Queue(s) Mem(GB): 100 available, 20 allocated, 0 pending, 0 reserved
Queue(s) VCores: 200 available, 2 allocated, 0 pending, 0 reserved

                  APPLICATIONID USER             TYPE      QUEUE   #CONT  #RCONT  VCORES RVCORES     MEM    RMEM  VCORESECS    MEMSECS %PROGR       TIME NAME
application_1484661449412_1115434 papp     mapreduce    default       3       0       3       0     16G      0G         28        172   5.00   00:00:00 EdmHdpIf-SRI
application_1484661449412_1115420 papp     mapreduce    default       2       0       2       0     12G      0G         86        545  95.00   00:00:00 oozie:launch
application_1484661449412_1115433 eapp     mapreduce       eapp       2       0       2       0     12G      0G         23        160   5.00   00:00:00 oozie:launch
application_1484661449412_1115386 eapp     mapreduce       eapp       2       0       2       0     12G      0G        250       1524  95.00   00:00:02 oozie:launch
[[email protected] sh]$ 
[[email protected] sh]$ 
[[email protected] sh]$ 
[[email protected] sh]$ 
[[email protected] sh]$ cat text1 | grep -A20 APPLICATIONID
                  APPLICATIONID USER             TYPE      QUEUE   #CONT  #RCONT  VCORES RVCORES     MEM    RMEM  VCORESECS    MEMSECS %PROGR       TIME NAME
application_1484661449412_1115434 papp     mapreduce    default       3       0       3       0     16G      0G         28        172   5.00   00:00:00 EdmHdpIf-SRI
application_1484661449412_1115420 papp     mapreduce    default       2       0       2       0     12G      0G         86        545  95.00   00:00:00 oozie:launch
application_1484661449412_1115433 eapp     mapreduce       eapp       2       0       2       0     12G      0G         23        160   5.00   00:00:00 oozie:launch
application_1484661449412_1115386 eapp     mapreduce       eapp       2       0       2       0     12G      0G        250       1524  95.00   00:00:02 oozie:launch
[[email protected] sh]$ 

Leave a Reply

Your email address will not be published. Required fields are marked *