How can i scan a file in a UNIX script and look for a particular keyword?
For example if i wanted to scan the file "lpcmp165.out" and see if it contains the term "error" or "ERROR" and then return a 0 or 1 or some indicator as such?
Detail example:
sqlplus -s xx/yyyyyyy#@zzz <<EOF > lpcmp165.out
set pagesize 0 feedback off verify off heading off echo off
set serveroutput on
DROP INDEX PKM_TCQ_DT_TPD_LOAN_EXLOAN_ID;
commit;
exit;
EOF
if [ lpcmp165.out contains "error" ] ; then <<<<< psuedo code
echo "bad result"
else
echo "good result"
fi
lpcmp165.out contains this output:
DROP INDEX xPKM_TCQ_DT_TPD_LOAN_EXLOAN_ID
*
ERROR at line 1:
ORA-01418: specified index does not exist
It is important to note that the option '-i' does not work as it
greps for more than just 'error' and 'ERROR':
'Error', 'eRROR', 'ErRoR', or any other combination of mixed cases.
The code does not work as written. Please try to run it. The return value from grep will not be used in the if statement. Perhaps you meant to add a "-c"?