title: How to use lines in a file as keyword for grep?
body: <p>I've search lots of questions on here and other sites, and people have suggested things that should fix my problem, but I think there's something wrong with my code that I just don't recognize. </p>
  
  <p>I have 24 .fasta files from NGS sequencing that are 150bp long. There's approximately 1M reads for each file. The reads are from targeted sequencing where we electroplated vectors with cDNA for genes of interest, and a unique barcode sequence. I need to look through the sequencing files for the presence or absence of the barcode sequence which corresponds to a specific gene. </p>
  
  <p>I have a .txt list of the barcodeSequences that I want to pass to grep to look for the barcode in the .fasta file. I've tried so many variations of this command. I can give grep each barcode individually but that's so time consuming, I know it's possible to give it the list of barcode sequences and search each .fasta for each of the barcodes and record how many times each barcode is found in each file. </p>
  
  <p>Here's my code where I give it each barcode individually:</p>
  
  <pre><code># Barcode 33
  mkdir --mode 755 $dir/BC33
  FILES="*.fasta"
  for f in $FILES;      do                      
  cat "$f" | tr -d "\n" | tr "&gt;" "\n" | grep 'TATTAGAGTTTGAGAATAAGTAGT' &gt; $dir/BC33/"$f"
                        done
  </code></pre>
  
  <p>I tried to adapt it so that I don't have to feed every barcode sequence in individually:</p>
  
  <pre><code>dir="/home/lozzib/AG_Barcode_Seq/"
  cd $dir
  FILES="*.fasta"
  for f in $FILES;      do                                              
  cat "$f" | tr -d "\n" | tr "&gt;" "\n" | grep -c -f BarcodeScreenSeq.txt | sort &gt; $dir/Results/"$f"
  echo "Finished $f"
                        done
  </code></pre>
  
  <p>But it is not searching for the barcode sequences. With this iteration it is just returning new files in the <code>/Results</code> directory that are empty. I also tried a nest loop, where I tried to make the barcode sequence a variable that changed like the <code>$FILES</code>, but that just gave me a new file with the names of my .fasta files:</p>
  
  <pre><code>dir="/home/lozzib/AG_Barcode_Seq/"
  cd $dir    
  FILES="*.fasta"
  for f in $FILES;      do                        
  for b in `cat /home/lozzib/AG_Barcode_Seq/BarcodeScreenSeq.txt`; do                   
  cat "$f" | grep -c "$b" | sort &gt; $dir/"$f"_Barcode
                        done   ;
                        done    
  </code></pre>
  
  <p>I want a output .txt file that has:</p>
  
  <pre><code>&lt;barcode sequence&gt;: &lt;# of times that bc was found&gt; 
  </code></pre>
  
  <p>for each .fasta file because I want to put all the samples together to make one large excel sheet which shows each barcode and how many times it was found in each sample. </p>
  
  <p>Please help, I've tried everything I can think of.</p>
  
  EDIT
  
  <p>Here is what the BarcodeScreenSeq.txt file would look like. It's just a txt file where each line is a barcode sequence: </p>
  
  <pre><code>head BarcodeScreenSeq.txt 
  TATTATGAGAAAGTTGAATAGTAG 
  ATGAAAGTTAGAGTTTATGATAAG 
  AATAGATAAGATTGATTGTGTTTG 
  TGTTAAATGTATGTAGTAATTGAG 
  ATAGATTTAAGTGAAGAGAGTTAT 
  GAATGTTTGTAAATGTATAGATAG 
  AAATTGTGAAAGATTGTTTGTGTA 
  TGTAAGTGAAATAGTGAGTTATTT 
  GAATTGTATAAAGTATTAGATGTG 
  AGTGAGATTATGAGTATTGATTTA
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>lozzib@gliaserver:~/AG_Barcode_Seq$ file BarcodeScreenSeq.txt
  BarcodeScreenSeq.txt: ASCII text, with CRLF line terminators
  </code></pre>