Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple grep of file

Status
Not open for further replies.

hubud

Instructor
Oct 18, 2002
123
GB
I have a script that analyses a list of files checking for various values and then reporting on this. I have just added a couple more greps to the script and it is now running in about 12 secs rather than the 2-3 it was before.

If a file is grepped and then grepped again straight away, does it use a cached copy of the file or re-read from the file on disk?

this may explain the time it takes to run

cheers

simmo
 
Can you post the script if you want some advices, please.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
space=' '
ls -1rt | tail -170 > $file


while read filename
do

tail -1 $filename | grep "failure" > /dev/null 2>&1

if [ $? = 0 ]
then

var1=`grep 'Initializing session' $filename`
var2=`echo $var1 | cut -d[ -f3`
var3=`echo $var2 | cut -d' ' -f1,3,4`

echo "$var3-- $filename: failed" >> $failures

grep "^ORA" $filename > /dev/null 2>&1

if [ $? = 0 ]
then
echo "$space Root cause; May have failed due to an ORA error" >> $failures
fi
grep "No such file or directory" $filename > /dev/null 2>&1

if [ $? = 0 ]
then
echo "$space Root cause; Source file not present" >> $failures
fi


#############################
#loads of greps on same file using same syntax
#############################

else
grep "^ORA" $filename > /dev/null 2>&1

if [ $? = 0 ]
then
echo "$filename: Failed due to an Ora error not detected by Informatica" >> $failures2
fi
fi


done<$file

Is this a bad way to do this?

cheers

simmo
 
It's better to use awk for tasks like this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top