2012-08-11 34 views

回答

0

如果你想使你的輸出更漂亮,使用column

$ printf "%s %s %s\n" one two three four five six seven eight nine 
one two three 
four five six 
seven eight nine 

$ printf "%s %s %s\n" one two three four five six seven eight nine | column -t 
one two three 
four five six 
seven eight nine 
0

最簡單的方法可能是使用格式寬度說明符。這取決於你的數據。

{ 
    for (i = 1; i <= NF; i++) { 
     printf("%9s ", $i); 
    } 
    printf("\n") ; 
} 

%9以上講述awk來打印這是寬9個字符的空間中的每個字段。如果數據寬於9個字符,awk將使用盡可能多的空間。

printf()非常靈活。例如,對於具有四個字段的輸入文件,可以執行此類操作來控制輸出格式。

printf("%d %9s  $d: %s\n", $1, $2, $3, $4); 

Format width in GNU gawk

0

這可能會爲你工作:

cat <<\! >file 
> a b c d 
> w x y z 
> ! 
cat file 
a b c d 
w x y z 
awk -v OFS='  ' '{$1=$1};1' file 
a  b  c  d 
w  x  y  z 
相關問題