such that the first column(which is identical across all the files) is preserved, but the other data fields are added onto the same line by comma(or space/tab) separation.
I am very new to shell scripting, hope to receive some kind advice on my question.
Hello frans,we can't use the join command directly to solve this problem.Because,mr_monocyte wants to deal with 1000 files not only two files which is accepted by join command.But,its a good idea if we have less number of files.mr_monocyte,use the following script to do your requirement.
k=0
for i in $* #reading the command line arguments which are all files given
do
k=0
while read line #reading line by line from the file
do
if [[ $i == $1 ]];then #checking whether the file received is first file
arr[$k]=$line
let k+=1
else
val=`echo $line | cut -d ' ' -f 1` #getting the first id to match
if [[ $val == `echo ${arr[$k]} | cut -d ' ' -f 1` ]];then #checking whether both the values are equal
result[$k]=${result[$k]},`echo $line | cut -d ' ' -f 2` #storing it in an array
let k+=1 #incrementing the array index
fi
fi
done < $i
done
for((l=0;l<${#result[@]};l++)) #traversing the list stored in an array
do
echo `echo ${arr[$l]} | cut -d ' ' -f 1`,`echo ${arr[$l]} | cut -d ' ' -f 2`${result[$l]} #printing the resulting output
#If you want the output to be in file,use the following command
echo `echo ${arr[$l]} | cut -d ' ' -f 1`,`echo ${arr[$l]} | cut -d ' ' -f 2`${result[$l]} >> result #printing the resulting output
done