Importing a bash array variable into GAWK (Was: something else)
From:
Stan Marsh
Subject:
Importing a bash array variable into GAWK (Was: something else)
Date:
Sun, 11 Jan 2026 04:14:54 -0700
So, I ended up with this:
--- Cut Here ---
someCommand | gawk '
ARGIND == 2 { getline t;foo[$0] = t; next }
...
' 'RS=\0' <(for i in "${!foo[@]}";do printf "%s\0" "$i"
"${foo[$i]}";done) RS=\n' -
--- Cut Here ---
A few comments:
1) The idea of using null terminated strings is good. Thanks for
that (*).
(*) But it then begs the question: But what if the data has nulls in
it? I did some testing and it seems that it is just not possible to
have nulls in a bash string. It is possible, BTW, for GAWK strings to
have nulls, but that doesn't have any effect here. So, we should be
OK.
Note also that the data in my actual use case for this is, in fact,
quite well behaved, so these considerations of handling weird data is
mostly of academic interest.
2) The version of bash in which I need this to work (5.1.8)
doesn't have @k. It has @K, but not @k. But the above "for" loop
seems to do exactly the same thing as would "little k".
3) Note that since I am piping the substantive data into gawk
(from someCommand), I need to use the <(...) form in order to
retrieve the "foo" data.
=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.
When responding to my posts, please try to refrain from giving bureaucratic
answers.
If you have nothing useful to say, then just click Next and go on.
[Prev in Thread]
Current Thread
[Next in Thread]
Importing a bash array variable into GAWK (Was: something else),
Stan Marsh<=