Dayton Rumbold
Dayton Rumbold

Reputation: 98

How can I change doubled-up quote characters to only one character with sed?

I have a tmp.cmd file I am stripping of specific quotation marks. It looks like this:

"grep -rFIil ""ACTVY_LOG""| xargs grep -iF ""ACTVY_ENT"""
"grep -rFIil ""ACTVY_LOG""| xargs grep -iF ""ACTVY_PTR"""

I want it to look like this:

grep -rFIil "ACTVY_LOG"| xargs grep -iF "ACTVY_ENT"
grep -rFIil "ACTVY_LOG"| xargs grep -iF "ACTVY_PTR"

I have been able to strip the first and last quotation using this command: sed -r 's/^"|"$//g' tmp.cmd > tmp1.cmd. So that it looks like this grep -rFIil ""APE.ACTVY_LOG""| xargs grep -iF ""ACTVY_ENT_TSTMP"".

How can I remove the other quotations? Thanks for any help.

Upvotes: 1

Views: 33

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295687

If you want to change "" to ", that's s/""/"/g.

Thus:

sed -e 's/^"//' -e 's/"$//' -e 's/""/"/g'

See this running against your stated input in an online sandbox at https://ideone.com/WOuXjU

Upvotes: 2

Related Questions