The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tail -f wannalearn Shell Programming and Scripting 4 04-10-2007 02:22 PM
Tail?? qfwfq Shell Programming and Scripting 7 06-18-2006 10:15 PM
tail command.. amon Shell Programming and Scripting 2 06-02-2006 01:36 AM
Help on scripting using tail jisc Shell Programming and Scripting 4 05-19-2006 12:15 AM
using tail -f cdunavent Shell Programming and Scripting 6 10-23-2002 02:10 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2005
Registered User
 

Join Date: Feb 2005
Posts: 68
how to sed with tail

hi,

I am searching error and exception in my log and >> to report file,
my code is :

sed -n '/[eE][rR][rR][oO][rR]/p;/[eE][xX][cC][eE][pP][tT][iI][oO][nN]/p' $ARIBA_LOG_DIR/MyLog.txt >> $LOG_ERR_REP

I need to report avove 5 line, that line and bellow 5 line..

what change is required in my code?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-30-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Using the shell, i'd do something convoluted like this
Code:
$ cat ./redlotus.sh
#!/bin/ksh

matchfile="redlotus.txt"

matches=`echo "${line}" | egrep -in "Error|Exception" ${matchfile}`
echo "${matches} " | while read line; do
   lineno=`echo "${line}" | cut -d: -f1`
   match=`echo "${line}" | cut -d: -f2`
   echo "Match found - line ${lineno} - ${match}"
   minline=$(( lineno - 5 ))
   [[ "$(( lineno - 5 ))" -lt 1 ]] && minline=1
   sed -n "$minline,$(( lineno - 1 ))p" ${matchfile}
   sed -n "$lineno p" ${matchfile}
   sed -n "$(( lineno + 1 )),$(( lineno + 5 ))p" ${matchfile}

   # note we could just do
   # sed -n "$minline, $((lineno + 5))p" ${matchfile}
   # but i've left this as-is to show you how to grab the previous, and the
   # next, five lines....
done
exit 0
No doubt, there is a far easier way (using -C option to GNU (e)grep for example)....

Cheers
ZB
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0