Bash paste command output formatting Bash paste command output formatting bash bash

Bash paste command output formatting


Could use sed after to remove tabs

 paste file file2 file3 | sed 's/\t/ /' 1 1 2 3 x x x 2 4 5   yy yy         zz

Here is a general purpose awk script that will work on any number of file with any formatting.

awk '    {x=ARGIND;a[x]=a[x]>(b=length($0))?a[x]:b}    {F[FNR,x]=$0}    END{            for(q=1;q<=FNR;q++)            {                    for(i=1;i<=ARGC;i++)                    {                    printf( "%-"a[i]"s ",F[q,i])                    }print ""            }    }' file{1,2,3,4)


paste twice makes it to me:

$ paste <(paste -d" " f1 f2) f31 1 2 3 x x x2 4 5   yy yy        zz


Just from you examples alone, it seems you could try first joining files 1 and 2, then joining that with file 3, but with a special delimiter, which you'd change later to a space.

Untested example:

paste -d" " file1 file2 | paste -d'|' - file3 | sed 's,|, ,g'

Here I used |, but you should use something you know for sure won't appear in the data i.e. something even more obscure like ˘. A bit of a hack, but should work.

For just two files:

paste -d'¤' file1 file2 | sed 's,¤, ,g'