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

[CLUG] Script : split a string

[CLUG] Script : split a string

Donal Hunt donal.hunt+clug at gmail.com
Sun Jan 11 22:35:05 GMT 2009


The following URL probably covers what you want (has examples for perl, ksh,
sh):
http://www.unix.com/shell-programming-scripting/38450-split-string-using-separetor.html
Regards

Donal

On Sun, Jan 11, 2009 at 10:10 PM, Jean-Pierre Thibert
<jpthibert at eircom.net>wrote:

> Hello there,
>
> I'm still working not learning script.
> My problem is:
>
> I get a variable from wget like
> DATA="Eddy,Murphy,Cork,125,95.41"
> String with comma separator
>
> I need to split every fields like
> FIRST_NAME="Eddy"
> NAME="Murphy"
> CITY="Cork"
> RUN=125
> AVERAGE=95.41
>
> What I learned so far let me think that script is file oriented, but I
> would like to use memory variables instead.
> I tried to use awk and I wrote
>
> awk -v INPUT=$DATA 'BEGIN { n = split(INPUT, parts, ",")}'
>
> As you can see INPUT passe the string into the "function" by value (I don't
> know if it's the good english expression). But is it a real function?
> parts is an array with the differents fields. The function works fine.
> print parts[1] works fine inside the function.
> My problem is I can't find out how to get the array out of the function.
> Any idea?
>
> But maybe there is another easier way to do that ????
>
> By the way, what is the usual way to write the variables, functions etc...
>  names? Capital? Lowercase? other?
>
> Thank you for your help
>
> --
> Jean-Pierre
>
> _______________________________________________
> Cork mailing list
> Cork at linux.ie
> http://mail.linux.ie/mailman/listinfo/cork
>


More information about the Cork 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