How can I align the columns of tables in Bash?

前端 未结 9 1999
一个人的身影
一个人的身影 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 09:05

    Not sure where you were running this, but the code you posted would not produce the output you gave, at least not in the bash that I'm familiar with.

    Try this instead:

    stringarray=('test' 'some thing' 'very long long long string' 'blah')
    numberarray=(1 22 7777 8888888888)
    anotherfieldarray=('other' 'mixed' 456 'data')
    array_size=4
    
    for((i=0;i

    Note that I'm using the group seperator character (1d) intead of tab, because if you are getting these arrays from a file, they might contain tabs.

提交回复
热议问题