Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sed to remove all double quotes within a file

Tags:

sed

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?

like image 439
MRTim2day Avatar asked Oct 03 '11 13:10

MRTim2day


People also ask

Does sed work with double quotes?

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 .

How do you trim double quotes in bash?

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 .


1 Answers

You just need to escape the quote in your first example:

$ sed 's/\"//g' file.txt 
like image 125
Vicky Avatar answered Sep 19 '22 14:09

Vicky