hi,
I need to get a string from a line matching the last occurrence of another string in a log file. I can get the last occurrence of in the log file like this:
perl -ne '$string=$_ if /Successfully sent/; END{print $string}' $log
+file
The line something like this:
2017-11-02 12:08:11,120 INFO [Timer-Driven Process Thread-8] o.a.nifi.
+remote.StandardRemoteGroupPort RemoteGroupPort[name=Receiver,targets=
+https://host.sub.domain.tld:9443/nifi] Successfully sent [StandardFlo
+wFileRecord[uuid=xxxxxxxxxxxx,claim=StandardContentClaim [resourceCla
+im=StandardResourceClaim[id=xxx, container=default, section=xxx], off
+set=384244, length=163820],offset=0,name=xxxxx.json,size=163820]] (15
+9.98 KB) to https://host.sub.domain.tld:9443/nifi-api in 242 millisec
+onds at a rate of 660.28 KB/sec
Now I need to get just the timestamp at the beginning of this line. This is how I thought it should work:
perl -ne '$string=$_ if /Successfully sent/; $string =~ /^(.*) INFO.*
+$/; END{print $1}' $logfile
But no success until now.
Any tips greatly appreciated. Thanks in advance!