title: bash search for string in each line of file
body: <p>I'm trying what seems like a very simple task: use bash to search a file for strings, and if they exist, output those to another file. It could be jetlag, but this should work:</p>
  
  <pre><code>#!/bin/bash
  
  cnty=CNTRY
  
  for line in $(cat wheatvrice.csv); do
      if [[ $line = *$cnty* ]]
      then
          echo $line &gt;&gt; wr_imp.csv
      fi
  done
  </code></pre>
  
  <p>I also tried this for completeness:</p>
  
  <pre><code>#!/bin/bash
  
  cnty=CNTRY
  
  for line in $(cat wheatvrice.csv); do
      case $line in 
      *"$cnty"*) echo $line &gt;&gt; wr_imp.csv;;
      *) echo "no";;
      esac
  done
  </code></pre>
  
  <p>both output everything, regardless of whether the line contains CNTRY or not, and I'm copy/pasting from seemingly reliable sources, so apparently there's something simple about bash-ness that I'm missing?</p>