Re: Splitting in shell (bash)

Liste des GroupesRevenir à cu shell 
Sujet : Re: Splitting in shell (bash)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shell
Date : 10. Nov 2024, 06:55:31
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vgphsj$9p84$1@news.xmission.com>
References : 1
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <vgo225$91aq$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
...
First note/caveat: I'm not interested in any solution involving IFS, for
two reasons:
   1) IFS-based solutions never work for me.
   2) Changing IFS is inherently dangerous, because, well, IFS itself in
inherently dangerous.  Yes, I know it has been somewhat de-fanged
recently - but it is still dangerous.
...
This works well, with a couple of caveats:
>
mapfile -td ';' <<< "$foo"
>
Caveats:
   1) You can only have one, single character delimiter.  It'd be nice if
you could have a reg-exp, like in GAWK.
   2) If the output you're processing comes from a process, as is usually
the case, special care must be taken:
>
mapfile -td ';' < <(someprocess | awk 1 ORS=)

It occured to me after posting this that a somewhat simpler approach would
be to just convert all the delimiters to newlines, like this:

mapfile -t < <(someprocess | sed 's/;/\n/g')

--
1) The only professionals who refer to their customers as "users" are
    computer guys and drug dealers.
2) The only professionals who refer to their customers as "clients" are
    lawyers and prostitutes.

Date Sujet#  Auteur
9 Nov 24 * Splitting in shell (bash)11Kenny McCormack
10 Nov 24 +* Re: Splitting in shell (bash)4Lem Novantotto
10 Nov 24 i`* Re: Splitting in shell (bash)3Lawrence D'Oliveiro
10 Nov 24 i +- Re: Splitting in shell (bash)1Lem Novantotto
17 Nov 24 i `- Re: Splitting in shell (bash)1Jerry Peters
10 Nov 24 `* Re: Splitting in shell (bash)6Kenny McCormack
10 Nov 24  `* Re: Splitting in shell (bash)5Axel Reichert
10 Nov 24   +* Re: Splitting in shell (bash)3Janis Papanagnou
10 Nov 24   i`* Re: Splitting in shell (bash)2Kenny McCormack
10 Nov 24   i `- Re: Splitting in shell (bash)1Janis Papanagnou
9 Dec 24   `- Re: Splitting in shell (bash)1Kenny McCormack

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal