On 10/25/2017 12:47 PM, Warren Young wrote:> > You?re making things hard on yourself by insisting on Bash, by the way. This solution is better expressed in Perl, Python, Ruby, Lua, JavaScript?probably dozens of languages.Yeah, you're right, I am. An associative array was the first thing I thought of, then realized BASH doesn't do those.? I honestly expected there to be a fairly straight forward way to do it in BASH, but I was sadly mistaken.? In my defense, I gave virtually no thought on the logic of what I was trying to do until after I'd committed significant time to a BASH script.? (Well maybe that's not a defense, but an indictment.) As I said, I don't do much scripting anymore as the majority of my time is spent DB tuning and Ansible automation.? Not really an excuse, and I appreciate your indulgence(s) in giving me a hand.? As embarrassed as I am, I'll just go sit in the corner the rest of the day. Thanks again. -- Mark Haney Network Engineer at NeoNova 919-460-3330 option 1 mark.haney at neonova.net www.neonova.net
On Oct 25, 2017, at 11:28 AM, Mark Haney <mark.haney at neonova.net> wrote:> > An associative array was the first thing I thought of, then realized BASH doesn't do those.But it does: in Bash 4, only. If you mean you must still use Bash 3 in places, then yeah, you?ve got a problem? one probably best solved by switching to some other language once the program grows beyond Bash 3?s natural scope. I was trying to think of which languages I know well which require even more difficult solutions than the Bash 4 one. It?s a pretty short list: assembly, C, and MS-DOS batch files. By ?C? I?m including anything of its era and outlook: Pascal, Fortran? I think even Tcl beats Bash 4 on this score, and it?s notoriously minimal in its feature set. Here?s a brain-bender: You could probably do it with sqlite3 with fewer lines of code than my Bash 4 offering. :)> I honestly expected there to be a fairly straight forward way to do it in BASH, but I was sadly mistaken.Oh, I don?t know, there must be a way to do it without associative arrays, but you?d only get points for the masochism value in doing without.
On 10/25/2017 3:34 PM, Warren Young wrote:> On Oct 25, 2017, at 11:28 AM, Mark Haney <mark.haney at neonova.net> wrote: >> An associative array was the first thing I thought of, then realized BASH doesn't do those. > But it does: in Bash 4, only. > > If you mean you must still use Bash 3 in places, then yeah, you?ve got a problem? one probably best solved by switching to some other language once the program grows beyond Bash 3?s natural scope. > > I was trying to think of which languages I know well which require even more difficult solutions than the Bash 4 one. It?s a pretty short list: assembly, C, and MS-DOS batch files. By ?C? I?m including anything of its era and outlook: Pascal, Fortran? > > I think even Tcl beats Bash 4 on this score, and it?s notoriously minimal in its feature set. > > Here?s a brain-bender: You could probably do it with sqlite3 with fewer lines of code than my Bash 4 offering. :) > >> I honestly expected there to be a fairly straight forward way to do it in BASH, but I was sadly mistaken. > Oh, I don?t know, there must be a way to do it without associative arrays, but you?d only get points for the masochism value in doing without.Array N holds the names and array T holds the totals.? For each line in the file, you iterate through N to find the name and then add the number to the same index in T (or create a new entry in both arrays if you don't find it).? Then you just have to iterate through both arrays and print off the names from N and the totals from T.? It's a pain, but it's doable. Sorry, I'm too lazy to write code for this...? :) -- Bowie
Once upon a time, Warren Young <warren at etr-usa.com> said:> I was trying to think of which languages I know well which require even more difficult solutions than the Bash 4 one. It?s a pretty short list: assembly, C, and MS-DOS batch files. By ?C? I?m including anything of its era and outlook: Pascal, Fortran?Heh, even C on SVR4 and newer (including POSIX from 2001) have pretty straight-forward hash routines: hcreate(), hsearch(), and hdestroy(). -- Chris Adams <linux at cmadams.net>