This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Compare fasta file with text file in bash script

Hi everyone ! I have some problems with my bash script. I have a text file( filt80more.txt) that contain my best alignments and I want to compare the alignments in that text file(filt80more.txt) with directory that contain all alignments(Tcoffee_outputs/E.aa.fa.aln) and take out that best alignments from directory(Tcoffee_outputs/E.aa.fa.aln) to my new folder (Filtrerad). I will be very grateful for your help :)

  for FILE1 in Tcoffee_outputs/E*.aa.fa.aln;
   do
    for FILE2 in `cat filt80more.txt`;
      do
       if [ $( diff "${FILE1}" "${FILE2}" ) == 0 ];
        then
mv Tcoffee_outputs/$FILE1~/Users/vazgengevorgyan/Desktop/perl_krill/merged_min_4_species_filtered/Filtrerad/$FILE1
       break
       fi
    done
   done
alignment bash script fast file text file

and what exactly is the problem with the script? (I'm not saying it's correct otherwise!). do you get any errors/warnings? or is it just not doing what you expect?

L.

Hi :) I get this error: diff: EOG090Y02RG: No such file or directory getfiles.sh: line 105: [: ==: unary operator expected

1 answer

Try this in the if statement :

if [ $( diff "${FILE1}" "${FILE2}" | wc -l ) == 0 ];

so add " | wc -l " to the if statement. this will check if there are differences reported (= line count will be > 0 )

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted. Upvote|Bookmark|Accept

Log in to answer this question.