Issue
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?
Solution
Using sed
$ echo "WARN (Periodic Recovery) IJ000906: error=15 check server.log" | sed 's/.*error=\([^ ]*\).*/\1/'
15
Answered By - HatLess Answer Checked By - Senaida (WPSolving Volunteer)