awk to output table-like or excel-like columns in linux terminal?

萝らか妹 提交于 2019-12-08 16:23:10

问题


I do a long pipe, that ends with ...| awk '{print $5"\t\t" $3"\t"$4}' in the Linux terminal. The columns are padded with tabs. The first column entries have different number of characters, so the second column results are not perfectly vertical. How to make the table look perfect?


回答1:


try to pipe the result to column -t:

...| awk '{print $5"\t\t" $3"\t"$4}'|column -t

hope it helps




回答2:


if your fields are tab separated the following one line script could print a table with cell borders

sed -e 's/\t/_|/g' table.txt |  column -t -s '_' | awk '1;!(NR%1){print "-----------------------------------------------------------------------";}'

Description            |value                 |Comment
-----------------------------------------------------------------------
Internal               |322                   |
-----------------------------------------------------------------------
External               |42515                 |
-----------------------------------------------------------------------


来源:https://stackoverflow.com/questions/12458729/awk-to-output-table-like-or-excel-like-columns-in-linux-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!