i=0
{ paste res.? res.?? res.???
while paste ./res."$((i+=1))"[0-9][0-9][0-9]
do :; done; } >outfile
I don't think this is as complicated as all that - you've already done the hard work by ordering the filenames. Just don't open all of them at the same time, is all.
Another way:
pst() if shift "$1"
then paste "$@"
fi
set ./res.*
while [ -n "${1024}" ] ||
! paste "$@"
do pst "$(($#-1023))" "$@"
shift 1024
done >outfile
...but I think that does them backwards... This might work better:
i=0; echo 'while paste \'
until [ "$((i+=1))" -gt 1023 ] &&
printf '%s\n' '"${1024}"' \
do\ shift\ 1024 done
do echo '"${'"$i"'-/dev/null}" \'
done | sh -s -- ./res.* >outfile
And here is yet another way:
tar --no-recursion -c ./ |
{ printf \\0; tr -s \\0; } |
cut -d '' -f-2,13 |
tr '\0\n' '\n\t' >outfile
That allows tar to gather all of the files into a null-delimited stream for you, parses out all of its header metadata but the filename, and transforms all lines in all files to tabs. It relies on the input being actual text-files though - meaning each ends w/ a newline and there are no null-bytes in the files. Oh - and it also relies on the filenames themselves being newline-free (though that might be handled robustly with GNU tar's --xform option). Given these conditions are met, it should make very short work of any number of files - and tar will do almost all of it.
The result is a set of lines that look like:
./fname1
C1\tC2\tC3...
./fname2
C1\tC2\t...
And so on.
I tested it by first creating 5 testfiles. I didn't really feel like genning 10000 files just now, so I just went a little bigger for each - and also ensured that the file lengths differed by a great deal. This is important when testing tar scripts because tar will block out input to fixed lengths - if you don't try at least a few different lengths you'll never know whether you'll actually handle only the one.
Anyway, for the test files I did:
for f in 1 2 3 4 5; do : >./"$f"
seq "${f}000" | tee -a [12345] >>"$f"
done
ls afterward reported:
ls -sh [12345]
68K 1 68K 2 56K 3 44K 4 24K 5
...then I ran...
tar --no-recursion -c ./ |
{ printf \\0; tr -s \\0; }|
cut -d '' -f-2,13 |
tr '\0\n' '\n\t' | cut -f-25
...just to show only the first 25 tab-delimited fields per line (because each file is a single line - there are a lot)...
The output was:
./1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
./2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
./3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
./4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
./5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25