Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed replace quotation marks

I have the string

"Motor des regionalen Neuen Forums"

and want to replace the quotation marks to have

\q{Motor des regionalen Neuen Forums}

gloablly in a file.

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

like image 708
Philipp Avatar asked Aug 07 '26 04:08

Philipp


1 Answers

You can use the following sed command:

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

See demo showing how this regex works. In sed, you just need to escape capturing parentheses ((...)) and the quantifier +. The escape symbol should be doubled to represent a literal \ in the replacement pattern, where a back-reference to the text matched with the first capturing group is used.

like image 197
Wiktor Stribiżew Avatar answered Aug 09 '26 18:08

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!