如果这是一个文件的输入
testabc Perf Agent data collector (26748) Running
midaemon Measurement Interface daemon (26565) Running
ttd ARM registration daemon (1779) Running
alarm Alarm generator (26764) Running
coda Performance Core COREXT Stopped
opcacta Action Agent AGENT,EA (26635) Running
opcle Logfile Encapsulator AGENT,EA (26613) Running
opcmona Monitor Agent AGENT,EA (26620) Running
opcmsga Message Agent AGENT,EA (26597) Running
opcmsgi Message Interceptor AGENT,EA (26641) Running
abcdccb Communication Broker CORE (26571) Running
ovcd Control CORE (26567) Running
ovconfd Config and Deploy COREXT (26588) Running
Message Agent is not buffering.
任何帮助都是非常感激的。只需要使用"awk",甚至不用nawk,因为大多数系统中都没有安装它。 try this;
awk '{print $NF}' <YourFile>
NF:给出记录中字段的总数
如果您已经安装了rev
,您可以使用它并处理第一列,然后再处理rev
:
rev < file | awk '{print $1}' | rev
您也可以使用cut
代替awk:
rev < file | cut -d' ' -f1 | rev
这就是我经常做的,它的速度快得惊人。
awk -F' ' '{print $NF}'
-F - delimiter(whitespace is the default)
$NF - last column, $(NF-1), last but one column and so on
AWK:
awk '$0=$NF""' file
将记录$0
替换为最后一个字段$NF
并打印