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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching backwards in a log file

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

I have some huge logfiles, where I want to find the last place ORA i written in it.

Normaly I youse 'more' and then '/ORA' to find it - but then I have to pres 'n' until it tells me that I've found the last one.

Is there any way to search backwards in a file?

Thanks
Larshg
 
Use :

cat <logfile> | grep &quot;ORA&quot; | tail -1

You'll get ther latest ORA error

windows : reboot Unix : be root
 
Hi

Yes thats true - but it only give me one line - and I need the information in the lines after ORA - its in those lines I can se what is realy wrong - ex. what database has a problem.

 
Try the following script :

#!/bin/ksh
typeset -i TOTAL=$(cat $1 | wc -l)
typeset -i LAST=$(grep -n &quot;ORA-&quot; $1 | tail -1 | cut -f 1 -d &quot;:&quot;)
typeset -i START=${TOTAL}-${LAST}+1
tail -${START} $1


windows : reboot Unix : be root
 
Well I couldn't quite get yours to work - but I changede it a little and then it works fine.

This is my script

TOTAL=`cat $2 | wc -l`
LAST=`grep -n &quot;$1&quot; $2 | tail -1 | cut -f 1 -d &quot;:&quot;`
((START= $TOTAL-$LAST+15 ))
tail -$START $2 |head -50


Thanks
Larshg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top