Supondo que a formatação é sempre como no exemplo - um valor ou delimitador de seção por linha:
awk '/\{/{s="";i=1}i{s=s"\n"$0}$1=="value3:"{v=$2}/\}/{if(V==""||V<v){V=v;S=s}i=0}END{print S}' json-like.file
Uma alternativa baseada em RS
, no caso de não conseguir os delimitadores de seção é aceitável:
awk -vRS='}' '{sub(/.*\{/,"")}match($0,/value3: (\S+)/,m)&&(v==""||v<m[1]){v=m[1];s=$0}END{print s}' json-like.file
Uma alternativa baseada em RT
:
awk -vRS='\{[^{}]+\}' 'match(RT,/value3: (\S+)/,m)&&(v==""||v<m[1]){v=m[1];s=RT}END{print s}' json-like.file
Explicações conforme solicitado no comentário.
awk '
/\{/{s="";i=1} # start of section? reset accumulated section data; set inside section flag
i{s=s"\n"$0} # inside section? append current record to the accumulated data
$1=="value3:"{v=$2} # value3 entry? store its value
/\}/{if(V==""||V<v){V=v;S=s}i=0} # end of section? if no previous max or previous max value less than current value then set maxvalue to value and max section to section; reset inside section flag
END{print S} # output max section
' json-like.file
awk -vRS='}' ' # record separator is the end of section delimiter
{sub(/.*\{/,"")} # remove start of section delimiter and anything before it
match($0,/value3: (\S+)/,m)&&(v==""||v<m[1]){v=m[1];s=$0} # current record contains value3 entry and no previous max or previous max value is less than its value? set max value to value and section to current record
END{print s} # output section
' json-like.file
awk -vRS='\{[^{}]+\}' ' # record separator is an entire section
match(RT,/value3: (\S+)/,m)&&(v==""||v<m[1]){v=m[1];s=RT} # current record terminator contains value3 entry and no previous max or previous max value is less than its value? set max value to value and section to current record terminator
END{print s} # output section
' json-like.file