Reputation: 43
I need to clear all characters but numbers and dots in a file.
The numbers are formatted as follows:
$(24.50)
Im using the following code to accomplish the task:
sed 's/[^0-9]*//'
It works but the last parenthesis is not removed. After running the code i get:
24.50)
I should get:
24.50
Please help
Upvotes: 0
Views: 1486
Reputation: 4612
Your regular expression is only matching a single instance of [^0-9.]*
. Namely, the $(
at the beginning. In order to get sed to match and replace all instances, you need to put a g
at the end, as in:
sed 's/[^0-9.]*//g'
The g
basically means "match this regular expression anywhere in the input". By default, it will only match on the first instance it encounters, and then stop.
Upvotes: 1