I have a file called file.txt. It has a number of double quotes throughout it. I want to remove all of them.
I have tried sed 's/"//g' file.txt
I have tried sed -s "s/^\(\(\"\(.*\)\"\)\|\('\(.*\)'\)\)\$/\\3\\5/g" file.txt
Neither have worked.
How can I just remove all of the double quotes in the file?
Single quotes tell shell to not perform any expansion at all and sed gets three arguments -n , /sweet/,$p , and file . When using double quotes, variables get expanded. Presuming variable=sweet and p not being set, second sed call got the following three arguments: -n , /sweet/, , and file .
A simple and elegant answer from Stripping single and double quotes in a string using bash / standard Linux commands only: BAR=$(eval echo $BAR) strips quotes from BAR . If you don't want anything printed out, you can pipe the evals to /dev/null 2>&1 .
You just need to escape the quote in your first example:
$ sed 's/\"//g' file.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With