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] awk and regular expression back referencing

[ILUG] awk and regular expression back referencing

Braun Brelin bbrelin at gmail.com
Fri Feb 5 14:04:39 GMT 2010


Thanks.

The correct answer to my problem should probably be "Use Perl"
:-)

Braun


On Fri, Feb 5, 2010 at 2:02 PM, <paul at clubi.ie> wrote:

> On Fri, 5 Feb 2010, Braun Brelin wrote:
>
>  /^([a-zA-Z]{5}).*/ {print (\1);}
>>
>
> It's worth noting that AWK splits lines into fields using the FS as input
> to a regular expression. You can dynamically change the FS as the programme
> goes along, e.g:
>
>  echo wootbabblahbaaabblob | awk '
>
> BEGIN {FS="ba*b"}
> {
>        for (i = 1; i <= NF; i++)
>                print $i
> }
>
> when given "wootbabblahbaaabblob" will print:
>
> woot
> blah
> blob
>
> You can change it as you go along too:
>
> $1 == "SetFS" { FS = $2 }
> $1 != "SetFS" && <other conditions and/or REs> { ... }
>
> though, setting the FS only affects splitting of the line prior the
> patterns being matched.
>
> You can also use 'split' to explicitly split a line.
>
> Not as powerful as you want, but hey.
>
>
> regards,
> --
> Paul Jakma      paul at jakma.org  Key ID: 64A2FF6A
> Fortune:
> The only possible interpretation of any research whatever in the `social
> sciences' is: some do, some don't.
>                -- Ernest Rutherford
>


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