grep lines having a text string from compressed files

The log of an application in my job is archived in a file, 1 file per day. I was requested to extract the activity of one client from these logs for the whole August, i.e., from 31 compressed files.

I placed all compressed log files into a folder called /database and I created a file to search and extract the log lines of my client. (If your *.gz  files are located somewhere else then pay attention to line 11 of tje script and modify it properly)


# author: tomeu.mir
# filename:
# desc  : search string in all *gz files and spools the output to a file
# usage : . <search string> <output filename>

for f in database/*.gz
  now=$(date +”%Y/%m/%d %T”)
  echo “[$now] Processing $f file with search string $search_string and output file $output_file”   
  zgrep -i “$search_string” $f >>  $output_file
now=$(date +”%Y/%m/%d %T”)
echo “[$now] done.”

Finally I executed the following:

$ . MYCLIENTNAME output.log

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s