awk line break after each file

前端 未结 3 1446
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 15:12

With this script every field is printed out according to the longest word of the current file, but needs to have a line break every file. How can this be achieved?



        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-28 15:41

    Took me some time, got it solved with this script.

    awk '{ NR>1 && FNR==1 ? l=length($0) && a[i++]= "\n" $0 : a[i++]=$0 }
    {if(NR>1 && FNR==1) for(e=(i-c);e<=(i-1);e++) b[e]=d ;c=FNR; d=l }
    { if( length($0) > l) l=length($0)+1 } 
    END{for(e=(i-c+1);e<=i;e++) b[e]=d; for(j=1;j<=i;j++) printf("%-"b[j]"s,",a[j-1] )}' infiles* >outfile
    

提交回复
热议问题