title: How to test for certain characters in a file
body: <p>I am currently running a script with an <code>if</code> statement. Before I run the script, I want to make sure the file provided as the first argument has certain characters. </p>
  
  <p>If the file does not have those certain characters in certain spots then the output would be <code>else "File is Invalid"</code> on the command line.</p>
  
  <p>For the <code>if</code> statement to be true, the file needs to have at least one <code>hyphen</code> in Field 1 line 1 and at least one <code>comma</code> in Field one Line one.</p>
  
  <p>How would I create an <code>if</code> statement with perhaps a test command to validate those certain characters are present? </p>
  
  <p>Thanks </p>
  
  <p>Im new to Linux/Unix, this is my homework so I haven't really tried anything, only brain storming possible solutions.</p>
  
  <pre><code>function usage
  {
    echo "usage: $0 filename ..."
    echo "ERROR: $1"
  }
  
  if [ $# -eq  0 ]
  then
    usage "Please enter a filename"
  else
    name="Yaroslav Yasinskiy"
    echo $name
    date
    while [ $# -gt 0 ]
    do
      if [ -f $1 ]
      then
        if            &lt;--------- here is where the answer would be
        starting_data=$1
        echo
        echo $1
          cut -f3 -d, $1 &gt; first
          cut -f2 -d, $1 &gt; last
          cut -f1 -d, $1 &gt; id
          sed 's/$/:/' last &gt; last1
          sed '/last:/ d' last1 &gt; last2
          sed 's/^ *//' last2 &gt; last3
          sed '/first/ d' first &gt; first1
          sed 's/^ *//' first1 &gt; first2
          sed '/id/ d' id &gt; id1
          sed 's/-//g' id1 &gt; id2
          paste -d\ first2 last3 id2 &gt; final
          cat final
          echo ''
      else
        echo
        usage "Coult not find file $1"
      fi
      shift
    done
  fi
  </code></pre>