cut或awk命令以打印第一行的第一字段 [英] cut or awk command to print first field of first row
本文介绍了cut或awk命令以打印第一行的第一字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试打印输出第一行的第一字段.就是这种情况.我只需要从此输出中打印SUSE
.
I am trying print the first field of the first row of an output. Here is the case. I just need to print only SUSE
from this output.
# cat /etc/*release
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 2
尝试过cat /etc/*release | awk {'print $1}'
,但会打印每行的第一个字符串
Tried with cat /etc/*release | awk {'print $1}'
but that print the first string of every row
SUSE
VERSION
PATCHLEVEL
推荐答案
Specify NR
if you want to capture output from selected rows:
awk 'NR==1{print $1}' /etc/*release
实现此目标的另一种方法( ugly )是:
An alternative (ugly) way of achieving the same would be:
awk '{print $1; exit}'
从特定行(例如第42行)获取第一个字符串的有效方法是:
An efficient way of getting the first string from a specific line, say line 42, in the output would be:
awk 'NR==42{print $1; exit}'
这篇关于cut或awk命令以打印第一行的第一字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文