Visit Our UNIX and Linux User Community


Problems with regular expressions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with regular expressions
# 1  
Old 04-16-2008
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
# 2  
Old 04-16-2008
Try...
Code:
grep "Batch exited with ERROR" Mytest.log | while read line
do
  : something with $line
done

# 3  
Old 04-16-2008
Quote:
Originally Posted by subin_bala
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
# 4  
Old 04-16-2008
Problems with regular expressions

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

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
# 5  
Old 04-16-2008
Try...
Code:
egrep "Batch .* ERROR" Mytest.log

# 6  
Old 04-16-2008
Thanks every one its working for me...

Previous Thread | Next Thread
Test Your Knowledge in Computers #601
Difficulty: Medium
Consider the Unix command sequence ps aux | grep -iv apache2 | wc -l This command will output the total number of apache2 processes running.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular Expressions

I am new to shell scripts.Can u please help me on this req. test_user = "Arun" if echo "test_user is a word" else echo "test_user is not a word" (1 Reply)
Discussion started by: chandrababu
1 Replies

2. Shell Programming and Scripting

Help with regular expressions

I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like: abc x93825 def 13234 x52673 hello output looks like: abc def 13234 hello Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
Discussion started by: pxalpine
7 Replies

3. Shell Programming and Scripting

Regular expressions help

need a regex that matches when a number has a zero (0) at the end of it so like 10 20 120 30 330 1000 and so on (6 Replies)
Discussion started by: linuxkid
6 Replies

4. Shell Programming and Scripting

Regular Expressions

what elements does " /^/ " match? I did the test which indicates that it matches single lowercase character like 'a','b' etc. and '1','2' etc. But I really confused with that. Because, "/^abc/" matches strings like "abcedf" or "abcddddee". So, what does caret ^ really mean? Any response... (2 Replies)
Discussion started by: DavidHe
2 Replies

5. UNIX for Dummies Questions & Answers

Regular expressions

In regular expressions with grep(or egrep), ^ works if we want something in starting of line..but what if we write ^^^ or ^ for pattern matching??..Hope u all r familiar with regular expressions for pattern matching.. (1 Reply)
Discussion started by: aadi_uni
1 Replies

6. UNIX for Advanced & Expert Users

regular expressions

I have a flat file with the following drug names Nutropin AQ 20mg PEN Cart 2ml Norditropin Cart 15mg/1.5ml I have to extract digits that are before mg i.e 20 and 15 ; how to do this using regular expressions Thanks ram (1 Reply)
Discussion started by: ramky79
1 Replies

7. Shell Programming and Scripting

Need help with Regular Expressions

Hi, In ksh, I am trying to compare folder names having -141- in it's name. e.g.: 4567-141-8098 should match this expression '*-141-*' but, -141-2354 should fail when compared with '*-141-*' simlarly, abc should fail when compared with '*-141-*' I tried multiple things but nevertheless,... (5 Replies)
Discussion started by: jidsh
5 Replies

8. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

9. UNIX for Dummies Questions & Answers

regular expressions

Hi Gurus, I need help with regular expressions. I want to create a regular expression which will take only alpha-numeric characters for 7 characters long and will throw out an error if longer than that. i tried various combinations but couldn't get it, please help me how to get it guys. ... (2 Replies)
Discussion started by: ragha81
2 Replies

10. Programming

regular expressions in c++

How do I use the regular expressions in c++? (2 Replies)
Discussion started by: szzz
2 Replies

Featured Tech Videos