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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -