ner*_*123 2 awk shell-script columns
我有一个文件,需要提取两列。
但是,我无法正确对齐它。我尝试使用column -t,但收到错误消息bash: column: command not found。
awk '{print $1" "$2}' | column -t
Run Code Online (Sandbox Code Playgroud)
如果您打印单独的输出字段并使用制表符作为输出字段分隔符,AWK 可以自行对齐其输出:
echo a b | awk -vOFS='\t' '{ print $1, $2 }'
Run Code Online (Sandbox Code Playgroud)
通过让 AWK 重建,您可以为任意数量的字段获得相同的效果$0:
echo a b c d | awk -vOFS='\t' 'NF > 0 { $1 = $1 } 1'
Run Code Online (Sandbox Code Playgroud)
printf如果您想要更复杂的输出,请查看 AWK 的功能。