fork download
  1. #!/bin/bash
  2.  
  3. awk 'BEGIN { insec=0 }
  4. /[^{]/ && NF==1 && !insec { sec=$1; next }
  5. /[{]/ && sec { insec=1; next }
  6. /[}]/ && insec { sec=""; insec=0; next }
  7. insec && !/^[ \t]*(value|type)/ && NF>1 { sub(/;$/, ""); printf "%s_%s=%s\n", sec, $1, $NF }
  8. insec && /^[ \t]*value/ { gsub(/[();]+/, ""); for(i=3; i<=NF; i++) printf "%s_%i=%s\n", sec, i-2, $i }'
Success #stdin #stdout 0.01s 5460KB
stdin
water
{
    nu              1.69e-3;
    rho             8;
}
vapour
{
    rho             2;
}
right
{
    type            zeroGradient 6;
    value           uniform (40 10 0);  

}

left
{
    value           uniform (0 5 0);    
}
stdout
water_nu=1.69e-3
water_rho=8
vapour_rho=2
right_1=40
right_2=10
right_3=0
left_1=0
left_2=5
left_3=0