How can I align the columns of tables in Bash?

前端 未结 9 2022
一个人的身影
一个人的身影 2020-12-02 08:25

I\'d like to output a table format text. What I tried to do was echo the elements of an array with \'\\t\', but it was misaligned.

My code

for((i=0;i         


        
9条回答
  •  日久生厌
    2020-12-02 08:51

    It's easier than you wonder.

    If you are working with a separated by semicolon file and header too:

    $ (head -n1 file.csv && sort file.csv | grep -v 
    ) | column -s";" -t

    If you are working with array (using tab as separator):

    for((i=0;i> tmp_file.csv
    
    done;
    
    cat file.csv | column -t
    

提交回复
热议问题