コマンド出力から行を削除する

コマンド出力から行を削除する

次のコマンドを実行しています。コマンドの出力をファイルに保存する必要がありますが、ヘッダーはありません。

私は試しました - yarn top | tail -n +8yarn topLinuxと同様にtop3秒ごとに更新され、出力を繰り返します)

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

期待される出力

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

答え1

この場合、grepを使用するのが最も効果的です。

1) yarn top | grep -A20 APPLICATIONID

- 文字列が一致した後にデータを印刷します。

20- (A) 文字列を一致させた後に印刷する行数

[gc13@oc1245342277 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
[gc13@oc1245342277 sh]$ 
[gc13@oc1245342277 sh]$ 
[gc13@oc1245342277 sh]$ 
[gc13@oc1245342277 sh]$ 
[gc13@oc1245342277 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
[gc13@oc1245342277 sh]$ 

関連情報