jeudi 11 juillet 2019

Else statement is not being executed - Unix

I am trying to run a bash script that has an if/else condition, but for some reason, my else statement is not being executed.

The rest of the script works perfectly. I could try to make it different, but I am trying to understand why this else is not working.

n=1
 for ((i=1;i<=GEN;i++))
 do
  if [ `cat sires${i} | wc -l` -ge 0 ] || [ `cat dams${i} | wc -l` -ge 0 ]; then
      cat sires${i} dams${i} > parent${i}
      awk 'NR==FNR {a[$1]=$0;next} {if($1 in a) print a[$1]; else print $0}' ped parent${i} >> ped_plus
      cat ped_plus | awk '$2!=0 {print $2,0,0}' | awk '!a[$1]++' > tmp_sire
      cat ped_plus | awk '$3!=0 {print $3,0,0}' | awk '!a[$1]++' > tmp_dam
      ((n2=n+i))
      awk 'NR==FNR {a[$1];next} !($1 in a) {print $0}' ped_plus tmp_sire > sires${n2}
      awk 'NR==FNR {a[$1];next} !($1 in a) {print $0}' ped_plus tmp_dam > dams${n2}
  else
      echo "Your file looks good."
      i=99
  fi
 done

It should print the message Your file looks good. , but this is not happing.
Any idea?

Aucun commentaire:

Enregistrer un commentaire