All I want to do is find out if the string 'NO' is in a file by checking for a return code of 0 if there is a match. The grep works fine on the command line directly naming the file but I am obviously not using the correct syntax within the shell script as I consistently get the error message
rep: 0652-033 Cannot open .
Please could you advise what brackets or other symbols need to be added or changed where?
vNoCheck= `grep 'NO' "$vOracount"`
if [ "$?" -ne "0" ]; then
echo 'No reconciliation needed'
fi
$vOraCount contains the file name, which I have checked by using echo i.e. $vOraCount= /badata/mtdata/extracts/RECON_HIST_PPP.txt
By the way I have just made a posting asking for recommended reading material so I can train myself in the mysteries of Unix punctuation and only go to forums with really difficult issues.
Thanks to both of you but unfortunately I am still getting the error message "grep: 0652-033 Cannot open ." for both of your options. I tried ${vOracount} but that made no difference.
I also tried
if `grep -q NO ${vOracount}`
then
echo 'No reconciliation needed'
This did not give me an error message but is not working - I changed the values in the file and it does not recognise the difference. I also tried
if `grep -q 'NO' ${vOracount}`
and again no error message but does not recognise different values in the file.
Advice would be gratefully received. Particularly after a 2.5 hour journey to work (walk, train, taxi instead of a 47 minutes car journey) - we Brits just can't cope with a few inches of snow