zsh-users
 help / color / mirror / code / Atom feed
* Re: lines as array elements
@ 1997-06-27 23:00 Steve Talley
  1997-06-28  5:15 ` Geoff Wing
  0 siblings, 1 reply; 4+ messages in thread
From: Steve Talley @ 1997-06-27 23:00 UTC (permalink / raw)
  To: unpingco; +Cc: zsh-users

Try:


#!/bin/zsh
 
IFS="
"
 
i=1;
for line in `cat file`
do
    x[$i]=$line
    i=`expr $i + 1`
done


Steve

> From zsh-users-request@euclid.skiles.gatech.edu Fri Jun 27 16:53 MDT 1997
> From: unpingco@mpl.ucsd.edu (Jose Unpingco)
> Subject: lines as array elements
> To: zsh-users@math.gatech.edu (zsh)
> Date: Fri, 27 Jun 1997 15:38:18 -0700 (PDT)
> 
> hi,
> 
> I have  a file that looks like this:
> 
>     -503  306 -498  428
>     -500  435 -501  588
>     -497  440 -501  593
>     -505  451 -502  601
>     -510  324 -511  454
>     -505  328 -511  459
>     -506  333 -509  464
>     -520  342 -492  463
> 
> what I'd like to do is get each line into an array element like
> 
> x[1]="-503  306 -498  428"
> 
> up to
> 
> x[8]="-520  342 -492  463"
> 
> I've tried x=(`cat file`) but that splits on the spaces between the
> numbers. I've looked at the IFS variable and tried to change it to
> newline but that doesn't work as expected.
> 
> Thanks. 
> 
> -- 
> Thank you for your time and consideration.  
> 
>              _ - - - _                             
>            /)-  - _     _                          
>           / |_o_/  -       _        
>               \__  -          _        
>                 \ \_              -   _  _  _  _   _  _  _  _  _       
>                  _                      
>    __ __ _ _  -        
> Jose Unpingco                                Mail Code ECE 0407
>                                              WK# (619) 534-5904
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lines as array elements
  1997-06-27 23:00 lines as array elements Steve Talley
@ 1997-06-28  5:15 ` Geoff Wing
  0 siblings, 0 replies; 4+ messages in thread
From: Geoff Wing @ 1997-06-28  5:15 UTC (permalink / raw)
  To: zsh-users

On 28 Jun 1997 09:05:49 +1000, Steve Talley wrote:

Just a couple of optimisations:

:#!/bin/zsh
: 
:IFS="
:"
: 
:i=1;
:for line in `cat file`

 for line in `< file`

:do
:    x[$i]=$line
:    i=`expr $i + 1`

     let i++

:done
-- 
Geoff Wing [mason@primenet.com.au]   Technical Manager
  Phone    : +61-3-9818 2977         PrimeNet - Internet Consultancy
  Facsimile: +61-3-9819 3788         Web : <URL:http://www.primenet.com.au/>
  Mobile   : 0412 162 441


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lines as array elements
  1997-06-27 22:38 Jose Unpingco
@ 1997-06-28  6:03 ` Zoltan Hidvegi
  0 siblings, 0 replies; 4+ messages in thread
From: Zoltan Hidvegi @ 1997-06-28  6:03 UTC (permalink / raw)
  To: Jose Unpingco; +Cc: zsh-users

> what I'd like to do is get each line into an array element like
[...]
> I've tried x=(`cat file`) but that splits on the spaces between the
> numbers. I've looked at the IFS variable and tried to change it to
> newline but that doesn't work as expected.

There were several solutions, but here is a simple one:

x=( "${(f)$(< file)}" )

Zoltan


^ permalink raw reply	[flat|nested] 4+ messages in thread

* lines as array elements
@ 1997-06-27 22:38 Jose Unpingco
  1997-06-28  6:03 ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Jose Unpingco @ 1997-06-27 22:38 UTC (permalink / raw)
  To: zsh

hi,

I have  a file that looks like this:

    -503  306 -498  428
    -500  435 -501  588
    -497  440 -501  593
    -505  451 -502  601
    -510  324 -511  454
    -505  328 -511  459
    -506  333 -509  464
    -520  342 -492  463

what I'd like to do is get each line into an array element like

x[1]="-503  306 -498  428"

up to

x[8]="-520  342 -492  463"

I've tried x=(`cat file`) but that splits on the spaces between the
numbers. I've looked at the IFS variable and tried to change it to
newline but that doesn't work as expected.

Thanks. 

-- 
Thank you for your time and consideration.  

             _ - - - _                             
           /)-  - _     _                          
          / |_o_/  -       _        
              \__  -          _        
                \ \_              -   _  _  _  _   _  _  _  _  _       
                 _                      
   __ __ _ _  -        
Jose Unpingco                                Mail Code ECE 0407
                                             WK# (619) 534-5904


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-06-28  6:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-27 23:00 lines as array elements Steve Talley
1997-06-28  5:15 ` Geoff Wing
  -- strict thread matches above, loose matches on Subject: below --
1997-06-27 22:38 Jose Unpingco
1997-06-28  6:03 ` Zoltan Hidvegi

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).