How to extract a value from a string using regex and a shell? -
i in shell , have string: 12 bbq ,45 rofl, 89 lol
using regexp: \d+ (?=rofl)
, want 45
result.
is correct use regex extract data string? best have done highlight value in of online regex editor. of time remove value string.
i investigating expr
, syntax errors.
how can manage extract 45 in shell script?
you can gnu grep's perl mode:
echo "12 bbq ,45 rofl, 89 lol"|grep -p '\d+ (?=rofl)' -o
-p
means perl-style, , -o
means match only.
Comments
Post a Comment