I'm having trouble writing a regular expression that matches the text I need it to. Let me give an example to express my trouble. Suppose I have the following text:
I want to find the line "find me" and match everything up from it to the nearest "else if(condition)". There can be anything at all between them, including newline characters. I tried the following regular expression:
Unfortunately the above regular expression does not do what I want. It finds the first "else if(condition)" and selects everything down to the first "find me" despite the nongreedy asterisk. Is there a way to match the "find me" first and then search up for for the "else if(condition)"?
Note: I know the above example doesn't make any sense code-wise. It's not the text I'm trying to match, but it's much less complicated and expresses what I'm trying to accomplish better.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
I like utility cgrep for situations like this. It allows one to specify conveniently a regular expression for the previous and succeeding boundaries -- "windows":
producong:
You will need to obtain, compile, and make available cgrep. See the URL mentioned in the script for that.
I need to pick a part of string lets stay started with specific character and end with specific character to replace using sed command
the line is like this:my audio book 71-skhdfon1dufgjhgf8.wav'
I want to move the characters beginning with - end before.
I have different files with random... (2 Replies)
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)
hi everybody
I am a new user to this forum and its previous posts have been very useful. I'm searching in a file using grep for patterns like
12.13.444
55.44.443
i.e. of form
<digit><digit>.<digit><digit>.<digit><digit><digit>
Can anybody help me with this.
Thanks in advance (4 Replies)
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)
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)
Hi,
below is a piece of code written by my predecessor at work.
I'm kind of a newbie and am trying to figure out all the regular expressions in this piece of code.
It is really a tough time for me to figure out all the regular expressions.
Please shed some light on the regular expressions... (3 Replies)
how to find for a file whose name has all characters in uppercase after 'project'?
I tried this:
find . -name 'project**.pdf'
./projectABC.pdf
./projectABC123.pdf
I want only ./projectABC.pdf
What is the regular expression that correponds to "all characters are capital"?
thanks (8 Replies)
I have following content in the file
CancelPolicyMultiLingual3=U|PC3|EN
RestaurantInfoCode1=U|restID1|1
.....
I am trying to use following matching extression
\|(+)
to get this
PC3|EN
restID1|1
Obviously it does not work.
Any ideas? (13 Replies)
How can i create a regular expression which can detect a new line charcter followed by a special character say * and replace these both by a string of zero length?
Eg:
Input File san.txt
hello
hi ... (6 Replies)