I've got the following code:
#!/bin/bash
while read line
do
echo "line" $line
if [[ -d ../Results/${line}_Forward && -d ../Results/${line}_Reverse ]]
then
cd ../Results/COMBI
mkdir ./${line}_COMBI
cd ..
for (( win = 2; win < 20; win += 2 )); do
printf 'The value of win is %d, now entereing inner loop\n' "$win"
for (( per = 50; per < 100; per += 2 )); do
printf 'Value of per is %d\n' "$per"
merger -asequence ./${line}_Forward/${line}_Forward_Trimmed_w${win}_p${per}.fa -bsequence ./${line}_Reverse/REV_COMP/${line}_Reverse_Trimmed_w${win}_p${per}_RevComp.fa -outseq ./COMBI/${line}_COMBI/${line}_w${win}_p${per}_COMBI.fa
done
done
else
echo $line "Forward or Reverse directory does not exist"
fi
done < ./Data_ORD.txt
When i run the script any dictory contained in the if statment exits but they actually do. And i get this kind of output for each line in Data_ORD.txt:
line ORD0926
Forward or Reverse directory does not exist
in the last echo
$line variable is not printed. I guess something is wrong with this variable but or with the if statement.
Any idea's why $line is not printed in the last echo and directories are not recognized by the if statement?
**.fa: fasta formats which are plain text formats containing DNA sequences. **merger command: contained in the EMBOSS package "The European Molecular Biology Open Software Suite"
cat -A
on your input file, see if it ends with a newline ( so look for$
in the last line ). If it doesn't, it can explain why lastecho
doesn't print out$line
. I can't see what potential issue withif
statement could be. Are you checking whether both directories exist or do you need to have just one exit ?echo ${line} | cut -c 1-7
and it solved the problem! what is used cat -A for?cat -A
shows the non-visible characters, for example newlines. Doprintf "one\ntwo" | cat -A
and you'll see what i meancat -A
on GNU, orcat -v
anywhere, also shows if the lines are terminated by Windows-style CRLF instead of LF; that would explain both the-d
tests failing and the 'missing' (actually overwritten) value in the error message for each line.${line:0:7}
Or you can remove the last char if it's CR with${line%$'\r'}