【发布时间】:2020-12-22 15:57:16
【问题描述】:
AIX 上的命令“(sleep 4 ; echo q) | topas -P |tee /tmp/top”在命令文本文件中生成此输出,我无法从中删除空格。我试过 sed/perl 和 awk 命令只打印包含字符的行,但没有任何帮助。我是否需要将此文件转换为 ASCII 文本格式才能使用 sed/per/grep 或 awk 来删除空行?
$ file /tmp/top
/tmp/top: commands text
$ head -n33 /tmp/top
DATA TEXT PAGE PGFAULTS
USER PID PPID PRI NI RES RES SPACE TIME CPU% I/O OTH COMMAND
root 9044256 20447712 60 20 2.43M 304K 2.43M 0:00 2.1 0 253 topas
root 14942646 8913178 60 20 72.0M 37.8M 72.0M 0:42 0.2 0 1 TaniumCl
root 20447712 21889434 60 20 148K 312K 508K 0:00 0.2 0 0 ksh
root 21955056 20447712 60 20 216K 36.0K 216K 0:00 0.1 0 3 sed
root 24838602 20447712 60 20 120K 8.00K 120K 0:00 0.1 0 1 tee
root 9830690 10355194 60 20 120K 4.00K 120K 0:00 0.1 0 0 sleep
root 12255642 13893896 60 41 57.5M 39.8M 57.5M 33:42 0.1 0 0 mmfsd
root 10355194 20447712 60 20 148K 312K 508K 0:00 0.1 0 0 ksh
root 9109790 4063622 39 20 12.9M 3.68M 12.9M 5:19 0.1 0 0 rmcd
root 13697394 4063622 60 20 8.27M 55.9M 8.27M 17:18 0.1 0 0 backup_a
root 20906328 1 60 20 1.81M 0 1.81M 3:15 0.0 0 0 nfsd
root 4260244 1 60 20 620K 88.0K 620K 41:23 0.0 0 0 getty
root 1573172 0 37 41 960K 0 960K 15:17 0.0 0 0 gil
nagios 9240876 4063622 60 20 23.7M 736K 23.7M 9:43 0.0 0 0 ncpa_pas
root 4391332 1 60 20 12.5M 252K 12.5M 4:43 0.0 0 0 secldapc
a_RTHOMA 8323456 12059082 60 20 636K 3.06M 1016K 0:00 0.0 0 0 sshd
root 8388902 4063622 60 20 1.76M 1.05M 1.76M 7:03 0.0 0 0 clcomd
root 3539312 1 60 20 448K 0 448K 5:07 0.0 0 0 lock_rcv
root 3670388 1 60 20 448K 0 448K 4:18 0.0 0 0 sec_rcv
root 5767652 4063622 48 8 392K 324K 392K 2:49 0.0 0 0 xntpd
root 6816242 1 60 20 1.19M 0 1.19M 1:05 0.0 0 0 rpc.lock
root 459026 0 16 41 640K 0 640K 2:19 0.0 0 0 reaffin
root 23921008 1 60 20 1.00M 0 1.00M 4:36 0.0 0 0 n4cb
lpar2rrd 23200112 25625020 64 22 868K 120K 868K 0:00 0.0 0 0 vmstat
root 7143896 1 40 41 448K 0 448K 0:48 0.0 0 0 nfsWatch
root 6160840 1 60 20 448K 0 448K 0:09 0.0 0 0 j2gt
【问题讨论】:
-
您是否尝试通过
od -c管道输出以查看这些空白行是否完全空白?另一种选择可能是只使用tail -n +7跳过前七行(如果空格数一致)。sed或awk你尝试过什么? -
od -c 会给我这样的东西:$ od -c /tmp/top 0000000 033 [ ? 1 小时 033 = 033 [ 3 9 ; 4 9 米 033 0000020 [ 4 0 米 033 [ ? 1 0 4 9 h 033 ( B 033 0000040 [ m 033 [ H 033 [ 2 J 033 [ 3 3 m T o 0000060 pas Monitorfor 0000100 host : 033 [ 3 7 mte 0000120 stsac 2 p 033 [ 3 3 m I 000010 : 033 [ 3 7 m tail -n +7 看起来更好
-
@ChrisJ,tail -n +7 似乎确实有效,我会测试并确认
-
@ronythomas,还是
awk '/^[a-zA-Z]+/' file一个?