LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-24-2010, 07:01 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Pattern matching with sed


Hi all,

In the below sentence, I am trying to match title="data under first Double quotes".
Code:
<A title="Puppy Linux 5.0 Released" href="http://lwn.net/Articles/388754/" rel=bookmark><FONT color=#ffffff size=2><STRONG>Puppy Linux 5.0 Released
</STRONG></A><STRONG> &nbsp;|&nbsp; </STRONG>
I am trying with
Code:
sed 's/title=".*"/news/' news
But this is matching title="Puppy Linux 5.0 Released" href="http://lwn.net/Articles/388754/". How to get rid of the greedy nature of regex ?

I came to know that I have to use '?' somewhere to get rid of this, But how ?

Thanks

Last edited by vinaytp; 05-24-2010 at 07:04 AM.
 
Old 05-24-2010, 07:21 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,353

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
Rather than "any char" I prefer "any non-terminating char" - when you know the terminating char; double quote in your case.
Code:
sed 's/title="[^"]*"/news/' news
Note that isn't an anchor in this context.
 
1 members found this post helpful.
Old 05-24-2010, 07:27 AM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by syg00 View Post
Rather than "any char" I prefer "any non-terminating char" - when you know the terminating char; double quote in your case.
Code:
sed 's/title="[^"]*"/news/' news
Note that isn't an anchor in this context.

Thanks it worked..
 
Old 05-24-2010, 07:33 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,562

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
Please mark as SOLVED if you have your answer
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SED multiline pattern matching AutoC Programming 1 07-18-2009 12:04 AM
sed: pattern matching with newlines anjanesh Linux - General 2 02-20-2009 06:36 AM
complicated pattern matching with awk or sed... alirezan1 Linux - Newbie 1 10-10-2008 06:45 PM
Sed pattern matching digitalbrutus Programming 1 08-20-2006 01:37 PM
pattern matching problem in sed digitalbrutus Programming 4 08-20-2006 04:40 AM


All times are GMT -5. The time now is 01:17 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration