Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove quotes surrounding number

I have a file with the lines looking similar to:

"somestring": "20.000",

I want to remove the quotes around 20.000.

Other use cases are

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

which should give

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

Obvious regex to recognize numbers is [0-9]+ and [0-9].[0-9]+ for decimals. I was told this is possible with the sed command as it can backreference, however I do not know how to use the sed command. Can someone please provide me with any linux command to accomplish this?

like image 548
Sahar Rabinoviz Avatar asked Oct 24 '25 17:10

Sahar Rabinoviz


1 Answers

$ sed -r 's@"([0-9]+(\.[0-9]+)?)",\s*$@\1,@' file
"somestring": 20.000,
"somestring": 20,
"somestring": "blahhhah 3",
"somestring": "",
like image 166
Gilles Quenot Avatar answered Oct 26 '25 08:10

Gilles Quenot



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!