LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Pattern matching with sed (https://www.linuxquestions.org/questions/linux-newbie-8/pattern-matching-with-sed-809757/)

vinaytp 05-24-2010 07:01 AM

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

syg00 05-24-2010 07:21 AM

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.

vinaytp 05-24-2010 07:27 AM

Quote:

Originally Posted by syg00 (Post 3979338)
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..

grail 05-24-2010 07:33 AM

Please mark as SOLVED if you have your answer


All times are GMT -5. The time now is 10:41 AM.