The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-12-2007
geekeezoid geekeezoid is offline
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
  #2 (permalink)  
Old 04-12-2007
ennstate ennstate is offline
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.
  #3 (permalink)  
Old 04-12-2007
geekeezoid geekeezoid is offline
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 04:47 PM..
  #4 (permalink)  
Old 04-12-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

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
  #5 (permalink)  
Old 04-12-2007
geekeezoid geekeezoid is offline
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
  #6 (permalink)  
Old 04-12-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

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
  #7 (permalink)  
Old 04-12-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Code:
awk '/^ERROR/ { end = NR+3 } NR < end { print }' report > new_file
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0