I have about 100s of files of type text in a known directory. I want to merge all files side by side. Number of lines in all the files will remain same.
For example file1 contains
cat
dog
File 2 contains
rat
mat
Output file should be
cat rat
dog mat
Using awk I was able to merge two files. But in the above mention method I want to merge 100s of files.
Thanks,
kantharaj.
what about this one:
for i in {1..100}
do
for f in a.txt b.txt
do
printf "%s" `head -$i $f|tail -1`
done
echo ""
done
Where variable i loops through the lines one by one
Would 'paste' be helpful?
not sure how paste would work with hundreds of files, but it will take a regular expression... i.e.
paste doc?.txt > combined.txt
will take all files doc?.txt files and paste them into combined.txt
just give a try to
paste doc*.txt >combined.txt
and see if you get what you need
paste takes wild card file names, I have just tried.
paste [abc].txt >combined.txt