ok, this is driving me crazy! I am trying to grep some info from a log file and add it to a summary in a email notification.
from log:
2019/07/22 11:36:03 [14396] Number of created files: 3 (reg: 2, dir: 1)
Now I want the print to be only the numbers at the end, 3, 2, 1 or maybe the entire last part 3 (reg: 2, dir: 1)
I have tried different things and this is the closest I got, but it only prints the number 3 and not the rest of the info I want.
nf=$(grep -o 'created files:' $logfile) | cut -d\ -f3)
Is this possible at all?
Edit:
Ok, so I got it working using nf=$(grep -Po 'created files: \K.*' "$logfile")
In my summary I add $nf to get the output like this Created $nf new files
giving me this result
Created 3 (reg: 2, dir: 1) new files
Now, can I somehow split it up even more so my result will be something like this? Created 1 directory and 2 files
Maybe using two separate grep commands to output the different variables, one for dir and one for reg on that line?
grep -o 'created files:.*'
orgrep 'created files:'
sincegrep -o
with a constant string pattern would only print that string.