开发者

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

开发者 https://www.devze.com 2023-04-10 12:47 出处:网络
I have a file called f开发者_运维知识库ile.txt.It has a number of double quotes throughout it.I want to remove all of them.

I have a file called f开发者_运维知识库ile.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?


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

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


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

tr -d "\""


For replacing in place you can also do:

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

or in Linux

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


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


Try this:

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


Try prepending the doublequote with a backslash in your expresssion:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号