I'm running the following command against a log file and only wanting to get the last/latest match. Sometimes there may only be one match, other times there may be multiple, which is causing an issue for me since the following command is returning both matches:
cat "$(ls -t | head -n1)" | grep -P "(NODE1[\s\S]*TEST\s=\sPOWER[\s\S]*OUTPUT\s=\s\d+?.*\s+;?)" >>>>> (results in)... NODE1 2018-03-06 12:01:23 TEST = POWER EVENT_TIME = 2018-03-06 12:01:23 OUTPUT = 12 ; NODE1 2018-03-06 12:03:23 TEST = POWER EVENT_TIME = 2018-03-06 12:03:23 OUTPUT = 7 ;
I need the last matching group in the event there are multiple. Is this possible with grep/regex or do I need to pipe the results into sed/awk? If so, how?