regexp: really tired, guru help needed...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting regexp: really tired, guru help needed...
# 1  
Old 11-23-2010
regexp: really tired, guru help needed...

Hello all! Please help me with the following complex regexp which works in egrep:

PHP Code:
egrep '\"http:\/\/ccc\.bbb\.com\/documents\/0000\/[0-9]{4}\/([^\.]+\.[a-z]{3})[^\"]*\"' my-file.html 
But silently does not work in sed:

PHP Code:
sed "s/\"http:\/\/ccc\.bbb\.com\/documents\/0000\/[0-9]{4}\/([^\.]+\.[a-z]{3})[^\"]*\"/aaa/g" my-file.html 
or

PHP Code:
sed 's/\"http:\/\/ccc\.bbb\.com\/documents\/0000\/[0-9]{4}\/([^\.]+\.[a-z]{3})[^\"]*\"/aaa/g' my-file.html 
Just can't figure out what's wrong...
# 2  
Old 11-23-2010
Try:
Code:
sed 's|"http://ccc\.bbb\.com/documents/0000/[0-9]\{4\}/[^.][^.]*\.[a-z]\{3\}[^"]*"|aaa|g' infile

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 11-23-2010
It works!!! Thank you!

Last edited by ulrith; 11-23-2010 at 10:03 AM..
# 4  
Old 11-23-2010
Could you give a sample of your input? (I adjusted my post, because you changed the name to ccc.bbb.com later BTW)
# 5  
Old 11-23-2010
Code:
sed 's/"http:\/\/ccc\.bbb\.com\/documents\/0000\/[0-9][0-9][0-9][0-9]\/[^.][^.]*\.[a-z][a-z][a-z][^"]*"/aaa/g' my-file.html

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 6  
Old 11-23-2010
I suppose your problem are some unescaped grouping constructs:

Your regex:
Code:
"/\"http:\/\/ccc\.bbb\.com\/documents\/0000\/[0-9]{4}\/([^\.]+\.[a-z]{3})[^\"] \"/

probably correct:

Code:
"/\"http:\/\/ccc\.bbb\.com\/documents\/0000\/[0-9]\{4\}\/\([^\.]+\.[a-z]\{3\}\)[^\"] \"/

If you want to repeat the previous regex part several times you have to use "regex\{<n>\}", not "regex{<n>}" and grouping has to be done with "\(<regex>\)", not "(<regex>)".

Furthermore, the "+" is not part of POSIX regexps, but some (usually GNU/Linux-) utilities understand it as "one or more", similar to "*" meaning "zero or more". I am not entirely sure how you meant it, but you would be probably better off making this clear by either escaping the "+" our using "<regex><regex>*" instead of "<regex>+" if you want to match one or more instances of <regex>.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 7  
Old 11-23-2010
Thank you all guys. You are really fast.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help from a C++ makefile guru

hello, i'm recompiling some c++ code for OSX and there are some bugs as the configure is not picking up some libs like atlas, pastix, etc, it should be finding either in standard path or with pkgconfig but it's not so i'm rewriting the Makefile. C++ territory is a bit of a stretch with all of... (0 Replies)
Discussion started by: f77hack
0 Replies

2. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

3. AIX

-- Need help from a AIX guru --

Hi alls I don't see any solution and I need to have feedback from other people... On a test machine (AIX 5.1) I've installed OpenSSH software on it (with openssl, prng, etc...) like is described on IBM AIX Docs. To control the installation I've rebooted the machine and all was ok (CDE was... (15 Replies)
Discussion started by: nymus7
15 Replies

4. Shell Programming and Scripting

scripting....guru's help needed

perl guru's, what i think is, not simply writing a script...i like to write a script which must take less time to run and less memory use..i like to fine tune my program... for ex, my program has a subroutine(1 file open &file close and 1print ) 2if loops(1 file open &file close and... (2 Replies)
Discussion started by: sekar sundaram
2 Replies

5. UNIX for Dummies Questions & Answers

To all the Java guru...

Please forgive me if this is the wrong place for this post. I didn't see a good place to post this topic in. :D I would like to know what's the most popular and reliable Java IDE out there nowadays? A FREE one would be awesome! :D Thanks for your suggestion! Cheers! (10 Replies)
Discussion started by: laila63
10 Replies

6. UNIX for Advanced & Expert Users

what do most Unix guru's use ? :D

I wanted to know what email app most Sun solaris / unix gurus use ? I have become quite NON microsoft in the last few months in my studying solaris.. thanks simon2000 (6 Replies)
Discussion started by: simon2000
6 Replies

7. UNIX for Dummies Questions & Answers

DNS guru needed...

Well I have a new hosting account. I love these guys, because they have everything I need, and give me everything I need, but at the cost of I must configure it myself. I am trying to create a subdomain, and they use raw zone access for dns administration. I have no idea how to configure the zone... (1 Reply)
Discussion started by: btmitch
1 Replies

8. UNIX for Dummies Questions & Answers

Give us your poor, your tired, your huddled Admins... War Stories

I have been toying with the idea of posting a thread asking for your dumbest mistakes so that we may all learn from each other. "A smart man learns from his own mistakes, A wise man learns from others' mistakes" I think I will start us off. I haven't had too many that were really bad, but... (6 Replies)
Discussion started by: Kelam_Magnus
6 Replies
Login or Register to Ask a Question