title: ksh: shell script to search for a string in all files present in a directory at a regular interval
body: <p>I have a directory (output) in unix (SUN). There are two types of files created with timestamp prefix to the file name. These file are created on a regular interval of 10 minutes.
  e. g: </p>
  
  <pre><code>1.  20140129_170343_fail.csv (some lines are there)
  2.  20140129_170343_success.csv (some lines are there)
  </code></pre>
  
  <p>Now I have to search for a particular string in all the files present in the output directory and if the string is found in fail and success files, I have to count the number of lines present in those files and save the output to the <code>cnt_succ</code> and <code>cnt_fail</code> variables. If the string is not found I will search again in the same directory after a sleep timer of 20 seconds.</p>
  
  <p>here is my code </p>
  
  <pre><code>#!/usr/bin/ksh
  
  for i in 1 2
  do
    grep -l 0140127_123933_part_hg_log_status.csv /osp/local/var/log/tool2/final_logs/* &gt;log_t.txt;  ###  log_t.txt will contain all the matching file list
    while read line   ### reading the log_t.txt
    do
      echo "$line has following count"
      CNT=`wc -l $line|tr -s " "|cut -d" " -f2`
      CNT=`expr $CNT - 1`
      echo $CNT
    done &lt;log_t.txt
    if [ $CNT &gt; 0 ]
    then
      exit
    fi
  
    echo "waiitng"
    sleep 20
  done
  </code></pre>
  
  <p>The problem I'm facing is, I'm not able to get the _success and _fail in file in line and and check their count</p>