Linux – Script for search string inside the file for every one hour

awkbashlinuxshell-scripting

I need to write a script where the particular string(alphanumeric) should be searched inside the file with every hour for whole day. And the search should not contain the previous hour results.

Time stamp format inside file is "2014-02-17 17:00:01"

The below command will give the out put for the whole day count but i need every hour count.

grep "recFileChg:true" *.tmp | awk -F "|" '{print $4, $29}' | cut -d "," -f1,2 | awk -F "[" '{print $1, $2}'

I would be very much appreciated if somebody can help me on this.

Best Answer

Well, it would be nice to have a line you have and a line you would like to get as the search result.

Anyway, I think it can be solved with just grep and cut:

grep "recFileChg:true" *.tmp | cut -f2- -d':' | cut -f2 -d'[' | cut -f1 -d':'
  • the first cut will strip the file name from the grep output
  • the second cut will strip everything up to the '[' character
  • the last cut will cut out the date and the hour