The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expressions ramky79 UNIX for Advanced & Expert Users 3 05-21-2008 02:13 PM
regular expressions melanie_pfefer UNIX for Dummies Questions & Answers 8 04-10-2008 01:24 AM
regular expressions ragha81 UNIX for Dummies Questions & Answers 2 03-05-2007 04:24 PM
regular expressions in c++ szzz High Level Programming 2 10-06-2003 07:33 AM
Regular expressions in sed mfreemantle UNIX for Dummies Questions & Answers 3 02-11-2002 06:34 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 46
Problems with regular expressions

Hi ,

I am reading data from a log file.
The log file will be like this :
19:40:25 DEBUG : Failed xml-common.noarch 0-0.6.3-18 - u
19:40:25 ERROR : Batch failed
19:40:25 DEBUG : Batch exited with ERROR 104
19:40:25 ERROR : Batch exited with ERROR 105
19:40:25 DEBUG : Batch exited with ERROR 104
19:40:25 INFO : Batch exited with ERROR 105


I am reading this log file line by line.
I need to store the line which contain " *Batch exited with ERROR *" in a variable using regular expressions.
I am triyng something like this

cat Mytest.log | while read data
do
TEST=`echo $data | grep __________
echo $TEST
done


Can any one complete my grep command ? or suggest any other logic?

Regards
Subin
Reply With Quote
Forum Sponsor
  #2  
Old 04-15-2008
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Try...
Code:
grep "Batch exited with ERROR" Mytest.log | while read line
do
  : something with $line
done
Reply With Quote
  #3  
Old 04-15-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 288
Quote:
Originally Posted by subin_bala View Post
Hi ,

I am reading data from a log file.
The log file will be like this :
19:40:25 DEBUG : Failed xml-common.noarch 0-0.6.3-18 - u
19:40:25 ERROR : Batch failed
19:40:25 DEBUG : Batch exited with ERROR 104
19:40:25 ERROR : Batch exited with ERROR 105
19:40:25 DEBUG : Batch exited with ERROR 104
19:40:25 INFO : Batch exited with ERROR 105


I am reading this log file line by line.
I need to store the line which contain " *Batch exited with ERROR *" in a variable using regular expressions.
I am triyng something like this

cat Mytest.log | while read data
do
TEST=`echo $data | grep __________
echo $TEST
done


Can any one complete my grep command ? or suggest any other logic?

Regards
Subin
just grep for the pattern which you want,it can be like this--

cat Mytest.log | while read data
do
TEST=`echo $data | grep -i "Batch exited with ERROR "`
echo $TEST
done
Reply With Quote
  #4  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 46
Problems with regular expressions

Thanks for all ur reply.
But still i have still some problems in it

19:40:25 DEBUG : Batch exited with ERROR 104
19:40:25 ERROR : Batch failed with ERROR 105
19:40:25 DEBUG : Batch stopped with ERROR 104


if the log file contain batch failed and batch stopped that also i need to store. means something like" *Batch*ERROR*".

Please any one can check this too

Regards,
Subin
Reply With Quote
  #5  
Old 04-15-2008
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Try...
Code:
egrep "Batch .* ERROR" Mytest.log
Reply With Quote
  #6  
Old 04-16-2008
Registered User
 

Join Date: Apr 2008
Posts: 46
Thanks every one its working for me...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:55 AM.


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

Content Relevant URLs by vBSEO 3.2.0