使用此脚本,每个字段都根据当前文件的最长单词打印出来,但每个文件都需要换行。如何做到这一点?
awk 'BEGIN{ORS="\n"}FNR=NR{a[i++]=$0; if(length($0) > length(max)) max=$0;l=length(max)} END{ for(j=1; j<=i;j++) printf("%-"(l+1)"s,",a[j-1])}' file1 file2 >outfile
文件 1
HELLO
WORLD
SOUTH IS
WARM
NORTH IS
COLD
文件2
HELLO
WORLD
SOUTH
WARM
NORTH
COLD
输出
HELLO ,WORLD ,SOUTH IS ,WARM ,NORTH IS ,COLD
HELLO ,WORLD ,SOUTH ,WARM ,NORTH ,COLD