Remove a character between 2 known strings

sedtext processing

I have a data set like below:

\"XXX \ START sapiodj \\" aj \d 2387 END hddo\" START bbcc  \\" END ss

My Requirement:
I want to remove all occurrences of backslash\ and double quotes " between START and END.

Desired Output:

\"XXX \ START sapiodj  aj d 2387 END hddo\" START bbcc   END ss

Note:

  1. Multiple START/END in same line
  2. I want to remove \ and " only between START and END and nowhere else
  3. And my file has multiple line (lines similar to what is shown above)
  4. I have to use sed only

I tried something like below (was trying to get rid of " alone first) and it didn't give me the desired result:

sed '/START/,/END/ s/"//g'

Best Answer

Assuming you don't have ` character in the file. If you do just change in the line bellow all ` to any other character that for sure will not be present in the input.

sed -e 's/END/`/g;:X' -e 's/\(START[^`]*\)["\]/\1/g;tX' -e 's/`/END/g'
Related Question