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?
If you notice awk 'print $1' prints first word of each line. If you use $3, it will print 3rd word of each line.
You use a dollar sign (' $ ') to refer to a field in an awk program, followed by the number of the field you want. Thus, $1 refers to the first field, $2 to the second, and so on. (Unlike in the Unix shells, the field numbers are not limited to single digits.
The `awk` command is one of many commands that can be used to print a range of columns from tabular data in Linux. The `awk` command is can be used directly from the terminal by executing the `awk` script file.
try to pipe the result to column -t:
...| awk '{print $5"\t\t" $3"\t"$4}'|column -t
hope it helps
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 |
-----------------------------------------------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With