Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to extract a percentage

Tags:

regex

linux

shell

I have strings like the following: blabla a13724bla-bla244 35%

Notice that there is always a space before the percentage. I would like to extract the percentage number (so, without the %) from these strings using the Linux shell.

like image 529
user1301428 Avatar asked Oct 24 '25 06:10

user1301428


1 Answers

Assuming you have GNU grep:

$ grep -oP '\d+(?=%)' <<< "blabla a13724bla-bla244 35%"
35
like image 87
glenn jackman Avatar answered Oct 25 '25 22:10

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!