Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

That secret you've been guarding, isn't.


comp / comp.unix.shell / Re: Splitting in shell (bash)

SubjectAuthor
* Splitting in shell (bash)Kenny McCormack
+* Re: Splitting in shell (bash)Lem Novantotto
|`* Re: Splitting in shell (bash)Lawrence D'Oliveiro
| +- Re: Splitting in shell (bash)Lem Novantotto
| `- Re: Splitting in shell (bash)Jerry Peters
`* Re: Splitting in shell (bash)Kenny McCormack
 `* Re: Splitting in shell (bash)Axel Reichert
  +* Re: Splitting in shell (bash)Janis Papanagnou
  |`* Re: Splitting in shell (bash)Kenny McCormack
  | `- Re: Splitting in shell (bash)Janis Papanagnou
  +- Re: Splitting in shell (bash)Kenny McCormack
  `- Re: Splitting in shell (bash)Kenny McCormack

1
Subject: Splitting in shell (bash)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Sat, 9 Nov 2024 16:19 UTC
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Splitting in shell (bash)
Date: Sat, 9 Nov 2024 16:19:17 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vgo225$91aq$1@news.xmission.com>
Injection-Date: Sat, 9 Nov 2024 16:19:17 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="296282"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

There is a feature that is prominently missing from the shell language (I
am speaking primarily of bash here) - which is the ability to split a
string on a delimiter. This is a common operation in most other
text-processing oriented languages (AWK, Perl, etc).

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.

Anyway, the point of this thread is that I have recently developed a good
solution for this, using bash's "mapfile" command. Suppose we have a
string in a variable (foo) like: foo;bar;bletch

I.e., with ; as the delimiter.

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=)

The point is that since ';' is now the delimiter, the newline at the end of
the line coming from someprocess is not treated as a delimiter, so it must
be disposed of with the AWK script. It'd be nice if you could make both
';' and '\n' be recognized as delimiters.

But other than those two caveats, it works well.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Cancer

Subject: Re: Splitting in shell (bash)
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 10 Nov 2024 00:51 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 00:51:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <vgp03e$iqq$1@dont-email.me>
References: <vgo225$91aq$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 10 Nov 2024 01:51:59 +0100 (CET)
Injection-Info: dont-email.me; posting-host="07b16a45fa6826731060500449e27693";
logging-data="19290"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NXpg+ufZ12/OB0WNeGPFAeKZ4omSjVFg="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:dKCVX/+cbWtClSPRq+6pxuQ7z4o=
View all headers

Il Sat, 9 Nov 2024 16:19:17 -0000 (UTC), Kenny McCormack ha scritto:

> 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
> inherently dangerous. Yes, I know it has been somewhat de-fanged
> recently - but it is still dangerous.

Sorry to bother you, but... could you please give me some hints? Why
dangerous? Thanks. :-)
> Anyway, the point of this thread is that I have recently developed a
> good solution for this, using bash's "mapfile" command.
> [...]
> mapfile -td ';' <<< "$foo"

Yes, mapfile is a good solution. Of course, when you use <<<, no word
expansion is performed, so IFS is out of the question.

> Caveats:
> 1) You can only have one, single character delimiter.

But you could have more using IFS. Something like:

| $ IFS=";:[ENTER]
| "
| $ declare myarray
| $ for i in $(echo "one:two;three 3[ENTER]
| four"); do myarray+=( $i ); done
| $ echo ${myarray[@]}
| one two three 3 four
| $ echo ${myarray[2]}
| three 3

What would be wrong with it?
--
Bye, Lem

Subject: Re: Splitting in shell (bash)
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 10 Nov 2024 01:25 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 01:25:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <vgp22t$268r$1@dont-email.me>
References: <vgo225$91aq$1@news.xmission.com> <vgp03e$iqq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 10 Nov 2024 02:25:50 +0100 (CET)
Injection-Info: dont-email.me; posting-host="860fb7f0885981f730bd58417c4f37b9";
logging-data="71963"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UTypGrUhbAVrVtyvMsR2K"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:KOgSI0ntQ7cyMJbS7ehFgFaCWi8=
View all headers

On Sun, 10 Nov 2024 00:51:58 -0000 (UTC), Lem Novantotto wrote:

> But you could have more using IFS.

IFS is the way to go.

If you want your change to IFS to be only temporary, you can restrict it
to a subshell by putting the code sequence in “( ... )”. But then you
cannot pass variables back to the parent shell.

Another option is to use a coproc command.

Subject: Re: Splitting in shell (bash)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Sun, 10 Nov 2024 05:55 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 05:55:31 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vgphsj$9p84$1@news.xmission.com>
References: <vgo225$91aq$1@news.xmission.com>
Injection-Date: Sun, 10 Nov 2024 05:55:31 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="320772"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

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.

Subject: Re: Splitting in shell (bash)
From: Axel Reichert
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 10 Nov 2024 08:14 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mail@axel-reichert.de (Axel Reichert)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 09:14:45 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <87msi74ia2.fsf@axel-reichert.de>
References: <vgo225$91aq$1@news.xmission.com>
<vgphsj$9p84$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 10 Nov 2024 09:14:46 +0100 (CET)
Injection-Info: dont-email.me; posting-host="92b2a7fd767833e89a614ce72197aac0";
logging-data="314380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6iCHLaL1T+sRjW5j2suHQ4RUIVzxPcN0="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:fe0N1hx38W4NJQ0Q+EeOFMC06sQ=
sha1:AkHe1UDd20coWxgh/RTyH2LKMug=
View all headers

gazelle@shell.xmission.com (Kenny McCormack) writes:

> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>> mapfile -td ';' < <(someprocess | awk 1 ORS=)

[...]

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

And in your original post you wrote:

There is a feature that is prominently missing from the shell language
(I am speaking primarily of bash here) - which is the ability to split
a string on a delimiter. This is a common operation in most other
text-processing oriented languages (AWK, Perl, etc).

So why bother with a shell solution and why bother with avoiding IFS,
when in the end you need to resort to AWK/sed anyway?

Do not get me wrong, I am learning a lot in this thread here, much of
the stuff is far beyond my level of expertise in shell programming, and
it would be great to have a shell-only solution for your inquiry, even
if only for "academic reasons" because, say, the solution (still to
come) may turn out to be too clumsy for daily use). I will applaud such
a result, but for the time being I would be happy if you could elaborate
somewhat more about your motivation for this exercise.

Best regards

Axel

Subject: Re: Splitting in shell (bash)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 10 Nov 2024 09:21 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 10:21:44 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <vgptv9$ahrg$1@dont-email.me>
References: <vgo225$91aq$1@news.xmission.com>
<vgphsj$9p84$1@news.xmission.com> <87msi74ia2.fsf@axel-reichert.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Nov 2024 10:21:46 +0100 (CET)
Injection-Info: dont-email.me; posting-host="7181a3b3bf83a0fb25d0aaf5f910f366";
logging-data="345968"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dxv8+zQAxAEy72MrIg4MG"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:6g3f5F/eCP9T0fYWqN5q1ICeyNQ=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <87msi74ia2.fsf@axel-reichert.de>
View all headers

On 10.11.2024 09:14, Axel Reichert wrote:
> gazelle@shell.xmission.com (Kenny McCormack) writes:
>
>> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>>> mapfile -td ';' < <(someprocess | awk 1 ORS=)
>
> [...]
>
>> mapfile -t < <(someprocess | sed 's/;/\n/g')
>
> And in your original post you wrote:
>
> There is a feature that is prominently missing from the shell language
> (I am speaking primarily of bash here) - which is the ability to split
> a string on a delimiter. This is a common operation in most other
> text-processing oriented languages (AWK, Perl, etc).
>
> So why bother with a shell solution and why bother with avoiding IFS,
> when in the end you need to resort to AWK/sed anyway?

If we're on a targeted platform, looking for a solution for a simple
function, but having made bad experiences with some technical detail
on the platform, then we're trying to peek in various directions to
find any (sufficiently acceptable) workaround. - Sort of; I guess.

(Personally I'd say that 'IFS' is not that bad to completely avoid
it. But I'm not the OP.)

>
> Do not get me wrong, I am learning a lot in this thread here, much of
> the stuff is far beyond my level of expertise in shell programming, and
> it would be great to have a shell-only solution for your inquiry, even
> if only for "academic reasons" because, say, the solution (still to
> come) may turn out to be too clumsy for daily use). I will applaud such
> a result, but for the time being I would be happy if you could elaborate
> somewhat more about your motivation for this exercise.

Since the OP is (usually) very clear about excluding some solutions
as acceptable by him I haven't bothered replying. - But if you're
asking I'd probably try for a shell-only solution along the way of
doing a substitution like arr=( ${var//[$'\n';]/|} ) to fill an
array, whereby defining 'IFS' appropriately (using the '|' here).
(This is just the outline of an idea not a solution, so be careful
with that fragment!)

To add another thought to the original question, and since I know
that the OP already has the relevant experience for that; for such
a basic function writing a shell built-in could be appropriate.
(That's not portable, but I think the OP doesn't care about that.)

Janis

>
> Best regards
>
> Axel
>

Subject: Re: Splitting in shell (bash)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Sun, 10 Nov 2024 09:32 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 09:32:10 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vgpuiq$9ur0$1@news.xmission.com>
References: <vgo225$91aq$1@news.xmission.com> <vgphsj$9p84$1@news.xmission.com> <87msi74ia2.fsf@axel-reichert.de> <vgptv9$ahrg$1@dont-email.me>
Injection-Date: Sun, 10 Nov 2024 09:32:10 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="326496"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <vgptv9$ahrg$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
....
>To add another thought to the original question, and since I know
>that the OP already has the relevant experience for that; for such
>a basic function writing a shell built-in could be appropriate.
>(That's not portable, but I think the OP doesn't care about that.)

Not a bad idea, actually.

In fact, one of my motivations for posting is the hope that a bash dev
might see this and be motivated to add the functionality to the shell.
Then I wouldn't have to write it myself.

That and/or be motivated to fix the IFS handling in the shell.

--
Marshall: 10/22/51
Jessica: 4/4/79

Subject: Re: Splitting in shell (bash)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 10 Nov 2024 13:05 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 14:05:29 +0100
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <vgqb2q$d0bp$1@dont-email.me>
References: <vgo225$91aq$1@news.xmission.com>
<vgphsj$9p84$1@news.xmission.com> <87msi74ia2.fsf@axel-reichert.de>
<vgptv9$ahrg$1@dont-email.me> <vgpuiq$9ur0$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Nov 2024 14:05:31 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d99559fe2737adea7678849905abed87";
logging-data="426361"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Mtum8EAZvd5cNUxyeaZf1"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:zbIs8FfPqCAlWAKSqIw0HJB9ACY=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <vgpuiq$9ur0$1@news.xmission.com>
View all headers

On 10.11.2024 10:32, Kenny McCormack wrote:
>
> In fact, one of my motivations for posting is the hope that a bash dev
> might see this and be motivated to add the functionality to the shell.
> Then I wouldn't have to write it myself.

:-)

>
> That and/or be motivated to fix the IFS handling in the shell.

What specifically are you referring to? - I can't imagine that there's
a bash specific bug with IFS since IFS handling is a very old concept
in Unixes' shell. - OTOH, I cannot think about changing long existing
behavior without breaking tons of code. This would at best [in bash]
lead to yet another 'shopt' setting to be explicitly activated. - But
how should it then behave?

Janis

Subject: Re: Splitting in shell (bash)
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 10 Nov 2024 13:28 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 10 Nov 2024 13:28:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <vgqcdv$bd34$1@dont-email.me>
References: <vgo225$91aq$1@news.xmission.com> <vgp03e$iqq$1@dont-email.me>
<vgp22t$268r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 10 Nov 2024 14:28:32 +0100 (CET)
Injection-Info: dont-email.me; posting-host="07b16a45fa6826731060500449e27693";
logging-data="373860"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Yq6xboAzLY/0EyMxdILilmnxmPLCBPIk="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:5XNluf1+/2ZWz3yR218zctCFNhA=
View all headers

Il Sun, 10 Nov 2024 01:25:49 -0000 (UTC), Lawrence D'Oliveiro ha scritto:

> IFS is the way to go.

I agree.

I've thought of it again, but besides the fact that IFS can handle only
one-char delimiters (which wasn't the matter in the OP's example)... I
actually cannot fancy any major issues with it (that furthermore would
need a fix). My bad, maybe.
--
Bye, Lem

Subject: Re: Splitting in shell (bash)
From: Jerry Peters
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 17 Nov 2024 00:43 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jerry@example.invalid (Jerry Peters)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Sun, 17 Nov 2024 00:43:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <vhbe7j$9aag$1@dont-email.me>
References: <vgo225$91aq$1@news.xmission.com> <vgp03e$iqq$1@dont-email.me> <vgp22t$268r$1@dont-email.me>
Injection-Date: Sun, 17 Nov 2024 01:43:33 +0100 (CET)
Injection-Info: dont-email.me; posting-host="eb164ba1c11e2b3c727b469ac2942a4e";
logging-data="305488"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XGXy+27aZb6fdGsJm0fz7gl37k/GvxVw="
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (Linux/6.6.61 (x86_64))
Cancel-Lock: sha1:weYwJRQt5+eWq5gv6zQqzXnYo+I=
View all headers

Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Sun, 10 Nov 2024 00:51:58 -0000 (UTC), Lem Novantotto wrote:
>
>> But you could have more using IFS.
>
> IFS is the way to go.
>
> If you want your change to IFS to be only temporary, you can restrict it
> to a subshell by putting the code sequence in ???( ... )???. But then you
> cannot pass variables back to the parent shell.
>
> Another option is to use a coproc command.

Or put it in a function and declare IFS local.
~$ xxx () { local IFS="$IFS|" ; echo "$IFS" ; }
~$ xxx

|
~$ echo $IFS

Subject: Re: Splitting in shell (bash)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Mon, 9 Dec 2024 12:32 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Splitting in shell (bash)
Date: Mon, 9 Dec 2024 12:32:41 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vj6o19$1frrq$1@news.xmission.com>
References: <vgo225$91aq$1@news.xmission.com> <vgphsj$9p84$1@news.xmission.com> <87msi74ia2.fsf@axel-reichert.de>
Injection-Date: Mon, 9 Dec 2024 12:32:41 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1568634"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <87msi74ia2.fsf@axel-reichert.de>,
Axel Reichert <mail@axel-reichert.de> wrote:
>gazelle@shell.xmission.com (Kenny McCormack) writes:
>
>> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>>> mapfile -td ';' < <(someprocess | awk 1 ORS=)
>
>[...]
>
>> mapfile -t < <(someprocess | sed 's/;/\n/g')
>
>And in your original post you wrote:
>
> There is a feature that is prominently missing from the shell language
> (I am speaking primarily of bash here) - which is the ability to split
> a string on a delimiter. This is a common operation in most other
> text-processing oriented languages (AWK, Perl, etc).
>
>So why bother with a shell solution and why bother with avoiding IFS,
>when in the end you need to resort to AWK/sed anyway?

Because I need the result in the shell script.

(Obviously) Re-writing the whole app in AWK is not an option. Certainly
not at this point in time.

>Do not get me wrong, I am learning a lot in this thread here, much of
>the stuff is far beyond my level of expertise in shell programming, and
>it would be great to have a shell-only solution for your inquiry, even
>if only for "academic reasons" because, say, the solution (still to
>come) may turn out to be too clumsy for daily use). I will applaud such
>a result, but for the time being I would be happy if you could elaborate
>somewhat more about your motivation for this exercise.

Primarily in the hopes that someone on the dev side of my chosen shell
(bash) will see it and say to themselves "Hey, that's a good idea."

I prefer to post about these sorts of things here (by "here", I mean
Usenet). I'm too lazy to participate in the "official" channels for the
FOSS software that I use.

--
Debating creationists on the topic of evolution is rather like trying to
play chess with a pigeon --- it knocks the pieces over, craps on the
board, and flies back to its flock to claim victory.

1

rocksolid light 0.9.8
clearnet tor