how to grep the contents of a variable..

Hello All,

I've written a script to collect all audit logs files; now i want to see only the files from it which contains certain x tablenames. I've stored all the tablenames in a log file and using it through variable in a script (ex:below)

$ more tablenames.log (this is just a samle tables there are more than 500 tables to search)
HRC1002
HRC1206
HRC1212
HRS1000
HRS1002
HRS1200
HRS1201

In a script:

TABLENAMES=/tmp/tablenames.log
SOURCE_FILES=/tmp/sys_audit_files.tmp
 
ls -1tr ${ORACLE_HOME}/rdbms/audit/*.aud > ${SOURCE_FILES}
(which collects more than 200 audit log files; and now i want to use a grep statment in a below for loop to search the tablenames.log file)
 
for i in `cat ${SOURCE_FILES}` ; do
    cat $i |  grep ?????? >> $LOGFILE
done

How do we use a variable or a logfile to grep

thanks in advance..

Use:

grep -f ${TABLENAMES} ${SOURCE_FILES}

instead of the for loop.

find ${ORACLE_HOME}/rdbms/audit -name "*.aud" -exec grep yourstring {} \; >> $LOGFILE

Edit: I see you want to grep for every pattern found in a file, so use Franklins method