问题
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