title: Shell script to check a log file and print the errors that are found in it
body: <p>I am pretty new to shell scripting . I am trying to write a script to check for logfile for errors (error strings are hardcoded), and i have to print the lines containing the error . i am able to write the logic but need pointers to read a file from user input.</p>
  <p>Appreciate the help thanks.</p>
  <hr />
  <h3>Logic:</h3>
  <ol>
  <li>Accept the logfile patch from user</li>
  <li>Check if the logfile is present or not</li>
  <li>If present search the file for lines containing the error string (eg. Error, ORA)</li>
  <li>Print the lines containing error strings , also write the output to a logfile</li>
  </ol>
  <hr />
  <p>Read the log file from user</p>
  <p>Set error strings</p>
  <pre><code>search=&quot;ERROR&quot;
  </code></pre>
  <p>set a path for output file</p>
  <pre><code>outfile=&quot;file1.txt&quot;
  </code></pre>
  <hr />
  <h3>Execution logic</h3>
  <pre><code>find &quot;$mydir&quot; -type f -name &quot;$filename&quot; |while read file
    do
      RESULT=$(grep &quot;$search&quot; &quot;$file&quot;)
        if [[ ! -z $RESULT ]]
           then
              echo &quot;Error(s) in $file: $RESULT&quot; &gt;&gt; &quot;$outfile&quot;
       fi
    done
  </code></pre>