Sample Header Ad - 728x90

Extracting positive/negative floating-point numbers from a string

4 votes
3 answers
22390 views
I am trying to extract numbers out of some text. Currently I am using the following: echo "2.5 test. test -50.8" | tr '\n' ' ' | sed -e 's/[^0-9.]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' This would give me 2.5, "." and 50.8. How should I modify the first sed so it would detect float numbers, both positive and negative?
Asked by ahajib (143 rep)
Jun 20, 2016, 07:28 PM
Last activity: Nov 13, 2024, 01:16 PM