OT parsovani retezce v bash
Tom Meinlschmidt
hw na meinlschmidt.org
Sobota Březen 24 20:39:36 CET 2018
jen pozor na ty mezery…
#!/usr/bin/env bash
text="jedna dva tri ctyri"
declare -a pole=($(echo "$text" | sed -e 's;[ ]{1,}; ;g'))
echo ${pole[0]}
echo ${#pole[@]}
> On Mar 24, 2018, at 20:32 , Admin HWnews <hwnews na cncnet.info> wrote:
>
> Diky moc tohle je fakt nejjednodussi.
>
> Dekuji, ale i vsem ostatnim.
>
> RV
>
> Dne 24.3.2018 v 20:13 Milan B. napsal(a):
>> Alebo bez read (ak by niekto namietal, ze read je externy program)
>> $ var="aaa bbb ccc ddd"
>> $ array=(${var})
>> $ echo ${array[0]}
>> aaa
>> $ echo ${array[1]}
>> bbb
>> On 24.03.2018 20:06, Milan B. wrote:
>>>
>>> V bashi, bez volania kdejakych externych programov:
>>>
>>> $ var="aaa bbb ccc ddd"
>>> $ read -a array <<< "${var}"
>>> $ echo ${array[0]}
>>> aaa
>>> $ echo ${array[1]}
>>> bbb
>>> $ echo ${array[2]}
>>> ccc
>>> $ echo ${array[3]}
>>> ddd
>>> $ echo ${array[4]}
>>>
>>> A dlzka pola:
>>>
>>> $ echo ${#array[@]}
>>> 4
>>>
>>>
>>>
>>> On 24.03.2018 19:31, Admin HWnews wrote:
>>>> Zdravim,
>>>>
>>>> poradite nejaky elegantni figl v bashi jak vybirat subretezce z radku?
>>>>
>>>> mam v promenne nacteno neco takoveho:
>>>>
>>>> par1<mezera>par2<mezera>par3....parn<CRLF>
>>>>
>>>> potreboval bych ty jednotlive hodnoty priradit do promennych - nepotrebuji vsechny takze by bylo idelani neco kde bych jako parametr zadal kolikaty parametr se ma priradit
>>>>
>>>> Samozrejme muzu na to neco otrockeho napsat, ale rad bych se naucili zase neco noeveho.
>>>>
>>>> Diky.
>>>>
>>>> RV
>>>> _______________________________________________
>>>> HW-list mailing list - sponsored by www.HW.cz
>>>> Hw-list na list.hw.cz
>>>> http://list.hw.cz/mailman/listinfo/hw-list
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> HW-list mailing list - sponsored bywww.HW.cz
>>> Hw-list na list.hw.cz
>>> http://list.hw.cz/mailman/listinfo/hw-list
>> _______________________________________________
>> HW-list mailing list - sponsored by www.HW.cz
>> Hw-list na list.hw.cz
>> http://list.hw.cz/mailman/listinfo/hw-list
> _______________________________________________
> HW-list mailing list - sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
www.meinlschmidt.com www.maxwellrender.cz
===============================================================================
Další informace o konferenci Hw-list