Re: Splitting in shell (bash)

Liste des GroupesRevenir à cu shell 
Sujet : Re: Splitting in shell (bash)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shell
Date : 10. Nov 2024, 10:21:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vgptv9$ahrg$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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
 


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