I'm new to unix/bash/code in general, and I'm trying to merge multiple sample files with the same name in different directories into a new file in its own directory (the outputs of multiple data collections).
To do this, I'm trying to create a script which uses two arrays - listA, the name of each sample file, and list B, the names for the newly merged sample files.
My code looks a little like this:
#!/bin/sh
listA=( old1 old2 old3 etc.)
listB=( new1 new2 new3 etc.)
i=0
for i in $listA $listB
do
cp ./folder1/$listA ./merged/$listB
cat ./folder2/$listA >> ./merged/$listB
cat ./folder3/$listA >> ./merged/$listB
cat ./folder4/$listA >> ./merged/$listB
((i=+1))
done
echo "Done stitching"
As is, it seems to merge the files for the first entry in listA into the first file in listB perfectly, but it won't repeat the process for the subsequent entries on the list.
Any advice to make this work as intended? Apologies for my ignorance, I'm very new to all of this and enjoying the learning process immensely - just a bit stumped.
file1
file2
and so on. Is it only the base name a difference between source and target filenames?listA
andlistB
? At the moment, they are two independent arrays. It'd be simpler to use a dictionary, if you are happy to use Bash 4.