我正在编写一个脚本来提取处理器集号,后跟bash shell中Solaris中该处理器集下的处理器in:
下面是我想要提取的输出:($output的内容)
user processor set 1: processors 0 1
user processor set 2: processors 2 8 9
user processor set 3: processors 3 4 5 6 7期望的输出为:
1: 0 1
2: 2 8 9
3: 3 4 5 6 7我使用nawk编写的代码如下:
print $output | nawk '
BEGIN { ORS="\n" ; OFS = " " }
{
print$4; print OFS
for (i=6;i<=NF;i++)
print $i
}'获取的输出:
1:
0
1
2:
2
8
9
3:
3
4
5
6
7有谁可以帮助我,让我知道我在获得所需输出的过程中遗漏了什么。提前谢谢。
编辑:使用OFS和ORS的想法可以从本教程获得:tutorial link
发布于 2011-05-07 05:50:36
默认情况下,ORS已设置为"\n"。由于您希望使用多个print语句,因此需要将其设置为空字符串,因为在任何print语句之后都有一个隐式的print ORS。
print $output | awk '
BEGIN { ORS=""; }
{
print $4;
for (i=6;i<=NF;i++)
print " " $i;
print "\n";
}'您也可以使用cut执行此操作:
print $output | cut -d ' ' -f 4,6-发布于 2011-05-07 05:55:49
尝尝这个
print $output | nawk '
BEGIN { ORS="\n" ; OFS = " " }
{
outrec = ""
for (i=6;i<=NF;i++)
outrec = outrec " " $i
print $4 " " outrec
}'https://stackoverflow.com/questions/5917322
复制相似问题