Split string into map (Associative Array)

Hi

Input:

{ committed = 782958592; init = 805306368; max = 1051394048; used = 63456712; }

Result:
A map (maybe Associative Array) where I can iterate through the key/value. Something like this:

for key in $map
do
  echo key=$key value=$map[$key]
done

Sample output from the map:

key=committed value=782958592
key=init value=805306368
key=max value=1051394048
key=used value=63456712

Tools (ordered):

  • bash
  • sed/awk
  • perl
  • python

Note:
Using bash 3 so I don't think it support Associative Array

something to start with:

awk -F'[{};=]' '{for(i=2;i<NF-1;i+=2) print $i "->" $(i+1)}' myFile

Change the input format some and you can do this

declare -A
aa=([committed]=782958592 [init]=805306368 [max]=1051394048 [used]=63456712)

echo ${aa[used]}
63456712
echo ${aa[max]}
1051394048

Sorry, I did not see the foor note before I post, but you can test it.