Regex – Remove quotation marks around numbers

Remove quotation marks around numbers… here is a solution to the problem.

Remove quotation marks around numbers

I have a file with lines similar to:

"somestring": "20.000",

I want to remove quotes around 20.000.

Other use cases are

:

"somestring": "20",
"somestring": "blahhhah 3",
"somestring": "",

Should give

"somestring": 20,
"somestring": "blahhhah 3",
"somestring": "",

The

obvious regular expressions that recognize numbers are [0-9]+ and [0-9].[ 0-9]+ for decimals.
I was told this can be achieved with the sed command because it can be backreferenced, but I don’t know how to use the sed command.
Can someone provide me with any linux command to accomplish this?

Solution

$ sed -r 's@"([0-9]+(\.[ 0-9]+)?)",\s*$@\1,@' file
"somestring": 20.000,
"somestring": 20,
"somestring": "blahhhah 3",
"somestring": "",

Related Problems and Solutions