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] [OT] awk FS question

[ILUG] [OT] awk FS question

Niall O Broin niall at magicgoeshere.com
Mon Sep 11 19:16:21 IST 2000


On Mon, Sep 11, 2000 at 06:16:30PM +0100, Mark Webb wrote:

> > From: Paul Jakma [mailto:paulj at itg.ie]
> > 
> > doc's for awk say the FS can be set to a regexp. I want FS to split
> > fields on spaces, tabs, etc and '/'.
> > 
> > I've tried 
> > 
> > FS = "[:space]\/"
> >    = "[[:space:]\/]"
> >    = "[\ /]"
> >    = "/[[:space:]/]"
> >    = "/[[\/[:space:]]"
> > 
> > and loads of combinations thereof.. just can not get it to fscking do
> > what i want.. arrgggg..
> 
> [mwebb at linux ~]$ cat m
> linewithnospaces
> a space tab/slash:colon
> 
>        ^___ tab
> 
> [mwebb at linux ~]$ cat p.awk 
> #
> #
> BEGIN   { FS="[ \t/]" }
> 
>         { print "[", $1, "] [", $2, "] [", $3, "] [", $4, "]" }
> 
> END     { }
> 
> [mwebb at linux ~]$ awk -f p.awk m
> [ linewithnospaces ] [  ] [  ] [  ]
> [ a ] [ space ] [ tab ] [ slash:colon ]
> 
> Easier than perl...

Well, I couldn't let that pass :-) . For the same file  m  I submit that

perl -F"[\s/]" -lane 'print "[ $F[0] ] [ $F[1] ] [ $F[2] ] [ $F[3] ]"' m

is "easier" although neither solution is easy if you don't know the
respective language :-) In either case, all the brackets that Mark threw in
make the solution a little less readable for those who don't know the
languages .


Regards,


Niall







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