In such situations, when there are explicit name = value operators in the record, I like to fill the array with these mappings first, for example:
map["<name>"] = <value>
and then just use the names to refer to the values โโI want. In this case:
$ awk -v RS= -F'\n' ' { delete map for (i=1;i<=NF;i++) { split($i,tmp,/ *= */) map[tmp[1]] = tmp[2] } } map["enable"] !~ /^0$/ { print map["name"] } ' file blue orange
If your version of awk does not support deleting an entire array, change delete map to split("",map) .
Compared to using RE and / or sub () s, etc., this makes the solution more reliable and extensible if you want to compare and / or print the values โโof other fields in the future.
source share