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

Kingsley G. Morse Jr. kingsley at loaner.com
Thu Dec 1 09:09:40 GMT 2011


Hi Marcus,

Here's a sample script that may help.

It echos your data into a pipe of two seds.

Maybe you can quickly and easily see it work by
using your mouse to copy and paste it into a
command line.



#!/bin/bash

echo "<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" | sed -E -n '/<tag>/{N; s/\n//; s/<tag>(.*)\(FR\)/<tag language="FR" attribute=\1>/g;p;}' | sed 's/> \?/>\n/g'



It seems to me that useful examples are at

    http://codesnippets.joyent.com/posts/show/2111

I hope that helps,
Kingsley

On 12/01/11 18: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.
> 
> Can anyone give some suggestions for doing such a multi-line regexp?
> 
> Thanks,
> Marcus.
> -- 
> Marcus Furlong
> -- 
> Irish Linux Users' Group mailing list
> About this list : http://mail.linux.ie/mailman/listinfo/ilug
> Who we are : http://www.linux.ie/
> Where we are : http://www.linux.ie/map/



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