I'd need to extract the value of a variable "error" from a log file. Here's a sample line:
WARN (Periodic Recovery) IJ000906: error=15 check server.log
I'd need to capture the value of "error". Looking on similar answers, I've come up with:
echo "WARN (Periodic Recovery) IJ000906: error=15 check server.log" | grep -P '\d+ (error=?)' -o
However it does not produce any value. Can you recommend a working solution for this case?
?is an operator, not a wild-card. You are trying to match the stringerrorfollowed by an optional=.errorwhen the character that precedes the blank beforeerroris:, not a digit.