#!/bin/bash

for file in *_prosco.json
do

if [ ! -L ${file} ]
then
  ab="$(echo ${file} |awk -F'_' '{print $2}')"
  if [ "$ab" == "angle" ]
  then
    #A_angle_C1p_C2p_C3p_prosco.json
    ln -s $file "$(echo ${file} |awk -F'_' '{print $1"_"$2"_"$5"_"$4"_"$3"_"$6}')"
    [[ "$file" =~ "r2" ]] && ln -s $file "$(echo ${file} | sed 's/r2//g' |awk -F'_' '{print $1"_"$2"_"$5"_"$4"_"$3"_"$6}')"
    [[ "$file" =~ "r2" ]] && ln -s $file "$(echo ${file} | sed 's/r2//g' |awk -F'_' '{print $1"_"$2"_"$3"_"$4"_"$5"_"$6}')"
  fi

  if [ "$ab" == "length" ]
  then
    #A_length_C1p_C2p_prosco.json
    ln -s $file "$(echo ${file} |awk -F'_' '{print $1"_"$2"_"$4"_"$3"_"$5}')"
    [[ "$file" =~ "r2" ]] && ln -s $file "$(echo ${file} | sed 's/r2//g' |awk -F'_' '{print $1"_"$2"_"$4"_"$3"_"$5}')"
    [[ "$file" =~ "r2" ]] && ln -s $file "$(echo ${file} | sed 's/r2//g' |awk -F'_' '{print $1"_"$2"_"$3"_"$4"_"$5}')"
  fi
fi

done

for file in U_*.json
do
  cp ${file} D${file}
done
rm DU_*O2p*
