I'm trying to grab the last space and what follows it on a line using grep.
This grab me the first space :
echo "toto tata titi" | grep -o " .*$"
In Java I would have used the non-greedy operator but it does not seem to work :
echo "toto tata titi" | grep -o " .*?$"
It return nothing
The expected result is titi
.
Replace .
with [^ ]
, which matches everything but space. Then it can be greedy.
echo "toto tata titi" | grep -o " [^ ]*$"
(If you want grep
to use extended regexes, either use egrep
or grep -E
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With