For example I want to change
"'this text'"
"that text"
'other_text'
into
'this text'
"that text"
'other_text'
I tried
sed -e 's/^"\'/"/g'
but my quoting must be off.
Ubuntu.
For example I want to change
"'this text'"
"that text"
'other_text'
into
'this text'
"that text"
'other_text'
I tried
sed -e 's/^"\'/"/g'
but my quoting must be off.
Ubuntu.
With GNU sed:
sed 's|\x22\x27|\x27|;s|\x27\x22|\x27|' file
Output:
'this text' "that text" 'other_text'
${single_quote}
${double_quote}
, this is readable but more characters.
– ctrl-alt-delor
Sep 17 '15 at 18:41
You can not use escape \
in a ''
quote. Therefore put everything in a ""
quote and escape the "
s. e.g. "s/^\"'/'/g"
Alternatively end the ''
quote, do a \'
, then start the ''
quote again e.g. 's/^"'\''/'\''/g'
Also if you are easily confused by the \
s and /
s, then note you do not have to use /
s as delimiters. You can use any character, e.g. "s%^\"'%'%g"
This only does the first quote at the beginning of line, the bit you seem to be struggling on.
Try this line
sed -e "s/^\"'/\'/g" -e "s/'\"$/\'/g" file
Instead of enclosing the sed
expression between ' '
, do it between " "
so you can escape with \
the " "
e.g.
@tachomi:~$ echo "\"'this text'\""
"'this text'"
@tachomi:~$ echo "\"'this text'\"" | sed -e "s/^\"'/\'/g" -e "s/'\"$/\'/g"
'this text'
e.g.2
@tachomi:~$ cat file.txt
"'this text'"
"that text"
'other_text'
@tachomi:~$ sed -e "s/^\"'/\'/g" -e "s/'\"$/\'/g" file.txt
'this text'
"that text"
'other_text'
-e
in one sed
e.g. sed -e "s/^\"'/\'/g" -e "s/'\"$/\'/g" file
– ctrl-alt-delor
Sep 17 '15 at 18:48