如何漂亮地打印逗号分隔文件?
How to pretty print a comma delimited file?
下面是我的文件。我试图在我的输出之间保持恒定的宽度,以便所有管道符号都在另一个下方,看起来像 table 格式。我怎样才能做到这一点?当我邮寄输出时,我也需要有相同的格式。
cat file.txt
name,score card,ID
Jack,Available,YES
Jen,NA,NO
Jerry,Available,YES
Padula,NA,YES
Mackenzi,NA,NO
sed 's/,/\t|\t/g' c.txt
name | score card | ID
Jack | Available | YES
Jen | NA | NO
Jerry | Available | YES
Padula | NA | YES
Mackenzi | NA | NO
==I want==
name | score card | ID
Jack | Available | YES
Jen | NA | NO
Jerry | Available | YES
Padula | NA | YES
Mackenzi | NA | NO
$ sed 's/,/,|,/g' file | column -t -s,
name | score card | ID
Jack | Available | YES
Jen | NA | NO
Jerry | Available | YES
Padula | NA | YES
Mackenzi | NA | NO
如果你想用 awk
、
存档也是一样
awk -F"," '{printf "%-10s%s%-10s%s%-10s\n", ,OFS,,OFS,}' OFS="|" file.txt
下面是我的文件。我试图在我的输出之间保持恒定的宽度,以便所有管道符号都在另一个下方,看起来像 table 格式。我怎样才能做到这一点?当我邮寄输出时,我也需要有相同的格式。
cat file.txt
name,score card,ID
Jack,Available,YES
Jen,NA,NO
Jerry,Available,YES
Padula,NA,YES
Mackenzi,NA,NO
sed 's/,/\t|\t/g' c.txt
name | score card | ID
Jack | Available | YES
Jen | NA | NO
Jerry | Available | YES
Padula | NA | YES
Mackenzi | NA | NO
==I want==
name | score card | ID
Jack | Available | YES
Jen | NA | NO
Jerry | Available | YES
Padula | NA | YES
Mackenzi | NA | NO
$ sed 's/,/,|,/g' file | column -t -s,
name | score card | ID
Jack | Available | YES
Jen | NA | NO
Jerry | Available | YES
Padula | NA | YES
Mackenzi | NA | NO
如果你想用 awk
、
awk -F"," '{printf "%-10s%s%-10s%s%-10s\n", ,OFS,,OFS,}' OFS="|" file.txt