Hello,
I want to merge multiple files (under hundreds folders) side by side. File name are the same but folder are different.
like
folder1/same_name.txt
folder2/same_name.txt
folder3/same_name.txt
......
Normally it can be done as
paste /different_path*/same_name.txt > merged_file.txt
but my challenge is I want to only merge the first 50 lines of each file as
head -50 folder1/same_name.txt | sort
head -50 folder2/same_name.txt | sort
...
head -50 folder299/same_name.txt | sort
to create intermediate files, then merge the intermediate files to have the result. I'd like to combine looping thru the folders with paste such as:
paste `head file*.txt | sort`
or
paste $(head file*.txt | sort)
Of course this did not work. My question is how to pipe the multiple "head | sort" with paste to have single line command.
Thanks a lot!