I have an output that looks like this
root@machine:path# someapp report | grep Lost
Lost Workers: 0
How can I grep only the digit at the end?
Thanks
I have an output that looks like this
root@machine:path# someapp report | grep Lost
Lost Workers: 0
How can I grep only the digit at the end?
Thanks
Like this:
someapp report | grep -i lost | tr -s ' ' | cut -d' ' -f4
Run app, pipe STDOUT through tr to remove runs of spaces, cut the new string using a space and then select the 4th field
test:
echo " Lost Workers: 0" | tr -s ' ' | cut -d' ' -f4
Combine search and parse with sed:
echo ' Lost Workers: 0' | sed -n '/Lost/ s/.*[[:blank:]]//p'
Pipelines that look like grep | cut ...
or grep | tr | cut
or similar are almost always better off using awk
:
$ printf 'foo\nLost Workers: 0\nbar\n' | awk '/Lost/{print $NF}'
0