Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

split string into array

22 views
Skip to first unread message

ice

unread,
Sep 15, 2012, 5:31:35 AM9/15/12
to
hi!

which of the following 2 methods is better?

list1=AAA#B#CCCCC#D#E#F#GG

1.
IFS=# read -r -a array1 <<< "$list1"

2.
array1=($(echo $list1|awk -F\# '{for (i=1; i<=NF; i++) printf "%s ",$i}'))

thanks

Mirko K.

unread,
Sep 15, 2012, 5:44:58 AM9/15/12
to
On 15.09.2012 11:31, ice wrote:
> hi!
>
> which of the following 2 methods is better?

None. ;-)

> list1=AAA#B#CCCCC#D#E#F#GG
>
> 1.
> IFS=# read -r -a array1 <<< "$list1"
>
> 2.
> array1=($(echo $list1|awk -F\# '{for (i=1; i<=NF; i++) printf "%s ",$i}'))
>
> thanks
>

$ list1=AAA#B#CCCCC#D#E#F#GG
$ IFS=# array=($list1)
$ echo ${array[2]}
CCCCC

0 new messages