Sed replace quotes

I have a line

"Motor des regionalen Neuen Forums"

      

and want to replace the quotes with

\q{Motor des regionalen Neuen Forums}

      

gloablly in the file.

How do I do this with sed? Or any other unix tool? Thanks to

+3


source to share


2 answers


You can use the following sed command:

sed 's/"\([^"]\+\)"/\\q{\1}/g' your_file

      



See a demo to show how this regex works. In sed, you just need to avoid capturing parentheses ( (...)

) and the quantifier +

. The equivalent character must be doubled to represent the literal \

in the replacement pattern, which uses a backreference to the text matched with the first capture group.

+1


source


sed -i.BACKUP "s / \" Motor \ des \ regionen \ Neuen \ Forums \ "/ \\ q {Motor \ des \ regionalen \ Neuen \ Forums} /" yourfile



The .BACKUP part just creates a backup named yourfile.BACKUP

-1


source







All Articles