Query Regarding Regular Expression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Query Regarding Regular Expression
# 1  
Old 03-24-2009
Query Regarding Regular Expression

Can you please tell me the meaning of .*

For eg. i have a text as "Scrapple the apple"

Now here, what does a.*e will match?
# 2  
Old 03-24-2009
It means "match any character, zero or more times, and be greedy about it". And for your text it will match "apple the apple"
# 3  
Old 03-24-2009
But it is not working in my case Smilie

dsing1@[/export/home/dsing1] $ --> more exp
scrapple the apple
dsing1@[/export/home/dsing1] $ --> grep a.*e exp
scrapple the apple
# 4  
Old 03-24-2009
Yes it is. grep returns the whole line if the regex is matching, not just the match.
# 5  
Old 03-24-2009
so when i do a.*e then how will i get "apple the apple" from "scrapple the apple"
# 6  
Old 03-24-2009
Code:
$ echo "scrapple the apple"|sed 's/s.*r//1'
apple the apple

Thanks
Sha
# 7  
Old 03-24-2009
Just as a hint, for source, listings, command line examples, ... please use the [code ][/code] tags (or the '#' symbol in the advanced editor), it's easier to read.
Code:
$ perl -pe 's/.*?(a.*e).*/$1/' exp

Other people can probably add more examples (awk anyone?)

Last edited by pludi; 03-24-2009 at 10:31 AM.. Reason: sed example already there
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with regular expression

Hi All We have a file with statements like below SELECT BLAH,BLAH,... FROM TABSCHEMA1.TABSCHEMA1 WITH UR SELECT BLAH,BLAH,... FROM TABSCHEMA2.TABSCHEMA2 WHERE BLAH=1 WITH UR . . . and so on We want the word Anything after FROM<SPACE> and stop when the word Encounter Space.... (11 Replies)
Discussion started by: mallak
11 Replies

2. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

3. Shell Programming and Scripting

?* regular expression in sh

Hi, what ?* means in sh script? I know that ? is equivalent to at least one appearance of a preceding expression and * is equivalent to at least one appearance of preceding expression but I have difficulties with a way in which I should interpret following pattern: -?* I would expect that... (4 Replies)
Discussion started by: DavidMax
4 Replies

4. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

5. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

6. Linux

Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression

Regular expression to extract "y" from "abc/x.y.z" (2 Replies)
Discussion started by: rag84dec
2 Replies

7. Shell Programming and Scripting

regular expression

Hello All! I have a file thats something like this: ( a grep output) /path/of/file/filename.abc.xyz.pqr:! Commented text /path/of/file/filename.abc.xyz: ! More Commented text I need to grep out those line from this file whose filename has ".abc" in the filename (anywhere in filename)... (3 Replies)
Discussion started by: ag79
3 Replies

8. Shell Programming and Scripting

Regular expression query in AWK

Hi, I have a string like this-->"After Executing service For 10 Request" in this string i need to extract "10". the contents of the string is variable and "10" appears before "For" and after "Request" i.e, in this format "For x Request" I need to extract the value of x. How to do this in AWK?... (10 Replies)
Discussion started by: omprasad
10 Replies

9. Shell Programming and Scripting

Regular expression query in AWK

I have a varable(var1) in a AWK script that contain data in the following format - I need to extract timestamp,priority and log message.I can extract these by using split function but i don't want to use it, since i want to extract it in one go. I have some difficulties in doing it using... (3 Replies)
Discussion started by: omprasad
3 Replies

10. Shell Programming and Scripting

Regular Expression + Aritmetical Expression

Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant. THX! (2 Replies)
Discussion started by: Z0mby
2 Replies
Login or Register to Ask a Question