Sam*_*Sam 7 bash shell terminal command-line
当我用输入文件键入此列命令时,我收到以下错误
column -t text.txt > output
column: line too long
column: line too long
column: line too long
column: line too long
column: line too long
column: line too long
Run Code Online (Sandbox Code Playgroud)
当我查看文件输出时,似乎没有打印文件的前半部分(从左到右).
有没有办法解决这个错误?有没有办法完全执行命令会做什么,否则没有这个错误?
样本输入(实际输入~640列)
column1 column2 column3 column4
03 2 45 3
5 6 7 8
Run Code Online (Sandbox Code Playgroud)
样本输出(实际输出~640列)
column1 column2 column3 column4
03 2 45 3
5 6 7 8
Run Code Online (Sandbox Code Playgroud)
你可以尝试一个天真的awk实现:
awk 'NR==FNR{for(i=1;i<=NF;i++)
max[i] = length($i) > max[i] ? length($i) : max[i]; next}
{ for(i=1;i<=NF;i++) printf "%-"max[i]"s ", $i; printf "\n"}' text.txt text.txt
Run Code Online (Sandbox Code Playgroud)