Reputation: 25
How do I extract 68
from v1+r0.68
?
Upvotes: 0
Views: 753
Reputation: 85913
Match the digit string before the end of the line using grep
:
$ echo 'v1+r0.68' | grep -Eo '[0-9]+$'
68
Or match any digits after a .
$ echo 'v1+r0.68' | grep -Po '(?<=\.)\d+'
68
Print everything after the .
with awk
:
echo "v1+r0.68" | awk -F. '{print $NF}'
68
Substitute everything before the .
with sed
:
echo "v1+r0.68" | sed 's/.*\.//'
68
Upvotes: 1
Reputation: 320
Using awk, returns everything after the last '.'
echo "v1+r0.68" | awk -F. '{print $NF}'
Upvotes: 4
Reputation: 4135
type man grep
and you will see
...
-o, --only-matching
Show only the part of a matching line that matches PATTERN.
then type echo 'v1+r0.68' | grep -o '68'
if you want it any where special do:
echo 'v1+r0.68' | grep -o '68' > anyWhereSpecial.file_ending
Upvotes: 0
Reputation: 195289
grep is good at extracting things:
kent$ echo " v1+r0.68"|grep -oE "[0-9]+$"
68
Upvotes: 1
Reputation: 98118
Using sed to get the number after the last dot:
echo 'v1+r0.68' | sed 's/.*[.]\([0-9][0-9]*\)$/\1/'
Upvotes: 1