Code:
for i in {1..22}
do
#--iterate over chromosomes
saveTemp=""
files_info="$(find $input_dir -name "*_CHR$i.info" | sort )"
files_list=""
#---split by new lines and make it array---
SAVEIFS=$IFS
IFS=$'\n'
files_info=($files_info)
IFS=$SAVEIFS
join -j 2 -o 1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.10,1.11,1.12,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,2.10,2.11,2.12 ${files_info[0]} ${files_info[1]} > $output_dir/"tempCHR_"$i".info"
SAVEtemp=$output_dir/"tempCHR_"$i".info"
printf "$i joined for first two files\n"
for (( x=2;x<${#files_info[@]};x++ ))
do
join -j 2 -o 1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.10,1.11,1.12,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,2.10,2.11,2.12 $SAVEtemp ${files_info[$x]} > $output_dir/"tempchr"$i"_"$x".info"
SAVEtemp=$output_dir/"tempchr"$i"_"$x".info"
done
mv $SAVEtemp $output_dir/"joined_CHR""$i"".info"
SAVEtemp=$output_dir/"joined_CHR""$i"".info"
printf "CHR $i is done for joining\n"
for w in ` awk '{print $2}' $SAVEtemp | grep -v "rs_id" `
do
st="" #start null string to concatenate
for (( x=0;x<${#files_info[@]};x++ ))
do
#--loop through files to grep the string
temp_st=$(grep -w $w ${files_info[$x]})
st=$st" "$temp_st
done
echo "$st" >> $output_dir/"cols_joined_CHR"$i".info"
done
printf "Proceseed files for $i chromosome!\n"
done