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
**********************************************************
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!