LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Multi line regular expression help

[ILUG] Multi line regular expression help

John McCormac jmcc at hackwatch.com
Thu Dec 1 08:17:01 GMT 2011


On 01/12/2011 07:25, Marcus Furlong wrote:
> Hi,
>
> I'm trying to do a multine regexp that matches the following expressions:
>
> <tag>(FR) text
>
> <tag>  - (FR) text
>
> <tag>  (FR)
> text
>
> <tag>
> (FR) text
>
> <tag>
>   - (FR) text
>
> <tag>
> othertext - (FR) text
>
> <tag>othertext - (FR) text
>
> <tag>othertext -
> (FR) text
>
> and replaces them with
>
> <tag language="FR">
> text
>
> As a bonus, if "othertext" exists, I'd also like to put that into an attribute.
>
> I have tried egrep, perl and sed but I cannot seem to get it. I can
> match the single line ones fine, but not the multi line ones. None of
> the examples I've seen online help me, apart from removing newlines
> altogether, but I cannot do that, as further processing depends on the
> newlines being there.

Well the /g global replace option might be a bit too greedy on this but 
it should span the newlines.
(eg: sed 's/<tag>/<tag language="FR">/g' )

You could temporarily replace the newlines with a character that does 
not normally appear and then change it back after processing. You could 
also loop over each individual line for the "othertext". With some 
flavours of regexp, you may have to escape the angle brackets. I think 
that sed has an -f option to read the regexps from a file so this might 
allow you to adopt a more understandable multi regexp approach without 
an awful one line regexp.

Regards...jmcc
-- 
**********************************************************
John McCormac  *  e-mail: jmcc at hosterstats.com
MC2            *  web: http://www.hosterstats.com/
22 Viewmount   *  Domain Registrations Statistics
Waterford      *  And Historical DNS Database.
Ireland        *  Over 275 Million Domains Tracked.
IE             *  http://www.hosterstats.com/blog
**********************************************************


More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell