performance of shell script ( grep command)

Hi,

I have to find out the run time for 40-45 different componets. These components writes in to a genreric log file in a single directory.

eg.

directory is LOG and the log file name format is generic_log_<process_id>_<date YY_MM_DD_HH_MM_SS>.log

i am taking the run time using the time mentioned in the log file name which is actuall the log file creation time (component start time) and component end time with the last modification time of the log file.

I have tested this and it is working fine for less no of file, but when i am executing it for a month the script is taking hell lot of time.

i am searching the following patterns to check run time for a partiular component

grep -wl "SOURCE=$COMPONENT" $(grep -wl "RUN_DATE=$SEARCH_DATE" $LOG/generic_log*

but as we have 40 components which runs on daily basis, so for 30 days we'll have around 1200 log files to search for 2 patterns, thats why the script is taking lot of time.

Can any one please advice me batter way to do this.

You could try to run those commands in parallel:

grep -Fwl "RUN_DATE=$SEARCH_DATE" $LOG/generic_log* |
  xargs grep -Fwl "SOURCE=$COMPONENT"

Is there a reason for only using xargs on one side of the pipe? I would have thought if there were too many arguments for the grep on the right the same would be true of the grep on the left, or is there some obscure reason I am missing? ( Wouldn't be the first time I am missing something... :slight_smile: )

The xargs here is not used to avoid the argument list too long error. I'm using it to pass the input as filename(s), not as STDIN.
Consider the following:

zsh-4.3.10[t]% print -l 1 2 > infile
zsh-4.3.10[t]% cat infile 
1
2
zsh-4.3.10[t]% grep -Fwl 1 infile | grep -Fwl 2
zsh-4.3.10[t]% grep -Fwl 1 infile | xargs grep -Fwl 2
infile