我正在以下命令运行;我需要将命令的输出存储在文件中,但没有标题。
我尝试过 - yarn top | tail -n +8
(就像yarn top
Linux 一样,top
它每 3 秒刷新一次并重复输出)
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
A - 匹配字符串后打印数据
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]$