MRTim2day
MRTim2day

Reputation: 695

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

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?

Upvotes: 63

Views: 165132

Answers (6)

Amita
Amita

Reputation: 71

Try this:

sed -i -e 's/\"//g' file.txt

Upvotes: 7

bsky
bsky

Reputation: 20242

For replacing in place you can also do:

sed -i '' 's/\"//g' file.txt

or in Linux

sed -i 's/\"//g' file.txt

Upvotes: 17

Penfold
Penfold

Reputation: 619

Are you sure you need to use sed? How about:

tr -d "\""

Upvotes: 37

Mike Q
Mike Q

Reputation: 7337

Additional comment. Yes this works:

    sed 's/\"//g' infile.txt  > outfile.txt

(however with batch gnu sed, will just print to screen)

In batch scripting (GNU SED), this was needed:

    sed 's/\x22//g' infile.txt  > outfile.txt

Upvotes: 5

Vicky
Vicky

Reputation: 13244

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

$ sed 's/\"//g' file.txt

Upvotes: 140

justadreamer
justadreamer

Reputation: 2450

Try prepending the doublequote with a backslash in your expresssion:

sed 's/\"//g' [file name]

Upvotes: 2

Related Questions