Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
BASH中的nawk和OFS问题_Bash_Shell_Pattern Matching_Design Patterns_Nawk - Fatal编程技术网

BASH中的nawk和OFS问题

BASH中的nawk和OFS问题,bash,shell,pattern-matching,design-patterns,nawk,Bash,Shell,Pattern Matching,Design Patterns,Nawk,我正在编写一个脚本,以提取处理器集编号,后跟bash shell中Solaris中该处理器集下的处理器ID: 下面是我想从中提取的输出:($output的内容) 期望输出为: 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

我正在编写一个脚本,以提取处理器集编号,后跟bash shell中Solaris中该处理器集下的处理器ID:

下面是我想从中提取的输出:($output的内容)

期望输出为:

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
}'
任何人都可以帮助我,让我知道我在获得所需输出时缺少了什么。 提前谢谢


编辑:使用OFS和ORS的想法来自本教程:

ORS
已默认设置为
“\n”
。由于要使用多个print语句,您需要将其设置为空字符串,因为在任何print语句之后都有一个隐式的
print ORS

print $output | awk '
    BEGIN { ORS=""; }
    {
        print $4;
        for (i=6;i<=NF;i++)
            print " " $i;
        print "\n";
    }'
试试这个

print $output | nawk '                                 
BEGIN { ORS="\n" ; OFS = " " }
{
outrec = ""
for (i=6;i<=NF;i++)
    outrec = outrec " " $i
    print $4 " " outrec
}'
打印$output | nawk'
开始{ORS=“\n”OFS=“”}
{
outrec=“”

对于(i=6;iThanks John…这是一个很棒的捕获…我不知道隐式印刷机。。。
print $output | awk '
    BEGIN { ORS=""; }
    {
        print $4;
        for (i=6;i<=NF;i++)
            print " " $i;
        print "\n";
    }'
print $output | cut -d ' ' -f 4,6-
print $output | nawk '                                 
BEGIN { ORS="\n" ; OFS = " " }
{
outrec = ""
for (i=6;i<=NF;i++)
    outrec = outrec " " $i
    print $4 " " outrec
}'