Paste side by side multiple files by numerical order Paste side by side multiple files by numerical order shell shell

Paste side by side multiple files by numerical order


If your current shell is bash: paste -d " " file{1..1000}


you need rename the files with leading zeroes, like

paste <(ls -1 file* | sort -te -k2.1n) <(seq -f "file%04g" 1000) | xargs -n2 echo mv

The above is for "dry run" - Remove the echo if you satisfied...

or you can use e.g. perl

ls file* | perl -nlE 'm/file(\d+)/; rename $_, sprintf("file%04d", $1);'

and after you can

paste file*


With zsh:

setopt extendedglobpaste -d ' ' file<->(n)

<x-y> is to match positive decimal integer numbers from x to y. x and/or y can be omitted so <-> is any positive decimal integer number. It could also be written [0-9]## (## being the zsh equivalent of regex +).

The (n) is the globbing qualifiers. The n globbing qualifier turns on numeric sorting which sorts on all sequences of decimal digits appearing in the file names.