I know this question has been asked and answered before, I have tried the code but I do not get a correct output.
I have 2 folders: vanila1 and vanila2, each has 400 files with similar names
ls vanila1
MB.2613.007_0021.ED4_KS1A29-7_338_all
MB.2613.007_0022.ED9_SD2A27-1_180_all
MB.2613.007_14.ED14_IA2A35-2_310_all
ls vanila2
MB.2613.007_0021.ED4_KS1A29-7_338_all
MB.2613.007_0022.ED9_SD2A27-1_180_all
MB.2613.007_14.ED14_IA2A35-2_310_all
I want to combine files with identical names and I am using this:
ls vanila1 | while read FILE; do
cat vanila1/"$FILE" vanila2/"$FILE" >> all_combined/"$FILE"
done
I do not get a correct output, the number of lines in combined file is more that the sum of file1 and file 2. Am I doing something wrong?
ls
. You should probably look into either usingfind
or simple shell globbing to get your list of files to process. Extensive further reading on the subject can be found here. – DopeGhoti Feb 14 '18 at 19:46>
or>>
. The only difference between the two is that>
overwrites the contents of the file if it already exists. – Nasir Riley Feb 15 '18 at 03:16