Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paste side by side multiple files by numerical order

Tags:

shell

paste

I have many files in a directory with similar file names like file1, file2, file3, file4, file5, ..... , file1000. They are of the same dimension, and each one of them has 5 columns and 2000 lines. I want to paste them all together side by side in a numerical order into one large file, so the final large file should have 5000 columns and 2000 lines.

I tried

for x in $(seq 1 1000); do 
paste `echo -n "file$x "` > largefile
done

Instead of writing all file names in the command line, is there a way I can paste those files in a numerical order (file1, file2, file3, file4, file5, ..., file10, file11, ..., file1000)?

for example:

file1

1 1 1 1 1
1 1 1 1 1 
1 1 1 1 1
...

file2

2 2 2 2 2 
2 2 2 2 2
2 2 2 2 2 
....

file 3

3 3 3 3 3 
3 3 3 3 3 
3 3 3 3 3
....

paste file1 file2 file3 .... file 1000 > largefile

largefile

1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
....

Thanks.

like image 373
user1687130 Avatar asked Jun 12 '13 20:06

user1687130


1 Answers

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

like image 198
glenn jackman Avatar answered Jan 03 '23 20:01

glenn jackman