In bash or any other shell, glob expansions are done in lexicographical order. When having files numberd, this sadly means that 11.txt < 1.txt < 2.txt
. This weird ordering comes from the fact that, lexicographically, 1 < .
(<dot>-character (".")).
So here are a couple of ways to operate on your files in order:
rename all your files:
for i in *.txt; do mv "$i" "$(sprintf "%0.5d.txt" ${i%.*}"); done
paste *.txt
use brace-expansion:
Brace expansion is a mechanism that allows for the generation of arbitrary strings. For integers you can use {n..m}
to generate all numbers from n
to m
or {n..m..s}
to generate all numbers from n
to m
in steps of s
:
paste {1..2000}.txt
The downside here is that it is possible that a file is missing (eg. 1234.txt
). So you can do
shopt -s extglob; paste ?({1..2000}.txt)
The pattern ?(pattern)
matches zero or one glob-matches. So this will exclude the missing files but keeps the order.