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
grep command christine33990 UNIX for Dummies Questions & Answers 11 05-05-2008 11:45 PM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-04-2007 11:59 PM
grep command help ishmael^soyuz Shell Programming and Scripting 4 07-11-2007 06:01 AM
grep command pmsuper UNIX for Dummies Questions & Answers 6 11-22-2006 03:12 AM
grep command debasis.mishra Shell Programming and Scripting 1 03-27-2006 10:53 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2007
Posts: 6
grep command help

Hello, im trying to grep the first 3 lines(starting with ERROR) from an output report and put it in a separate file... any help would be appreciated. Below is the message contained in the report

ERROR >Invalid basic data (CMOFCT-5070)
Cusip: 05950XAL0 CMO#508039 Tra# 11 rec# 175
Firts Int Pay Date: 1061110
Bond type flag: V
Floater type Flag: 3
Floater Reset Start Date: 0
Floater Reset Frequency: 0

thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Give this a try,

grep -n "^ERROR" /tmp/err | head -3

INPUT:
HTML Code:
cat /tmp/err
ERROR:Quota exceeded
MISC
DEBUG
WARNING
ERROR
FAULT ERROR
DEBUG ERROR
ERROR TYPE 1
SEVERE ERROR
ERROR EXITING
OUTPUT
HTML Code:
1:ERROR:Quota exceeded
5:ERROR
8:ERROR TYPE
Thanks
Nagarajan Ganesan.
Reply With Quote
  #3 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2007
Posts: 6
Hi thanks for the help.. unfortunately it didnt work.. maybe im explainin it wrong... i am running a file and it spits out an output file r.(filename) and in that output file it has several messages... im lookin to take out the first 3 lines of messages that start with ERROR and put it into another file named geek... thanks

Last edited by geekeezoid; 04-12-2007 at 01:47 PM.
Reply With Quote
  #4 (permalink)  
Old 04-12-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
geekeezoid,
See if this would work for you:
sed -n '/ERROR/,$p' input_file | head -3
Reply With Quote
  #5 (permalink)  
Old 04-12-2007
Registered User
 

Join Date: Apr 2007
Posts: 6
Hi, thanks... i think it took out the first 3 lines of the first ERROR message.. but there are several ERROR messages in the r. output file... any way to take the first 3 lines of all the ERROR messages? thanks
Reply With Quote
  #6 (permalink)  
Old 04-12-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Geekeezoid,
Try this one:
Code:
mTotal=0
while read EachLine
do
 if [[ $mTotal -gt 0 ]]; then
   echo $EachLine
   mTotal=$mTotal+1
   if [[ $mTotal -gt 2 ]]; then
     mTotal=0
   fi
 else
   mCnt=`echo $EachLine | egrep -c "ERROR"`
   if [[ $mCnt -ne 0 ]]; then
     echo $EachLine
     mTotal=1
   fi
 fi
done < input_error_file
Reply With Quote
  #7 (permalink)  
Old 04-12-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,497
Code:
awk '/^ERROR/ { end = NR+3 } NR < end { print }' report > new_file
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:17 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