Issue
I only want to remove the first and last double quote
input:
word1 -word2 {word3} -word4 {"word5 'word6' "word7 word8" .word9"} -word10 (word11)
word1 -word2 {word3} -word4 {"word5 'word6' word7 word8 .word9"} -word10 (word11)
word1 -word2 {word3} -word4 {"word5 'word6' "word7 (word8)" .word9"} -word10 (word11)
Expected output:
word1 -word2 {word3} -word4 {word5 'word6' "word7 word8" .word9} -word10 (word11)
word1 -word2 {word3} -word4 {word5 'word6' word7 word8 .word9} -word10 (word11)
word1 -word2 {word3} -word4 {word5 'word6' "word7 (word8)" .word9} -word10 (word11)
Tried this to remove the first " but does not work
sed 's/"\({\)/\1/g' inputfile > outputfile
Removing the first double quote found in line, that is after a "{" and before a "}" can be accepted.
Assuming word can be different length too.
Solution
You may use this sed with a capture group:
sed -E 's/\{"(.*)"}/{\1}/' file
word1 -word2 {word3} -word4 {word5 'word6' "word7 word8" .word9} -word10 (word11)
word1 -word2 {word3} -word4 {word5 'word6' word7 word8 .word9} -word10 (word11)
word1 -word2 {word3} -word4 {word5 'word6' "word7 (word8)" .word9} -word10 (word11)
Here pattern {"(.*)"}
matches longest match between {"
and "}
and captures test in the middle into a capture group.
Answered By - anubhava Answer Checked By - Terry (WPSolving Volunteer)