Você pode, de fato, combinar awk
e grep
:
awk 'BEGIN{rv=1} # Default return value is 1
tolower($0) ~ /^some_phrase/{ # Case insensitive search
if($2 != ""){ # If $2 is not empty,
print $2 # print the value,
rv=0 # and set the return value
}
exit # one match, do not process any more line
}
END{exit rv}
' test.txt