Reputation: 497
I took a dump from postgres which created a bunch of CSVs, which have single (') and double (") characters in a few huge files.
How can I replace these with \" and \' in linux?
Thanks!
Upvotes: 0
Views: 254
Reputation: 785721
You can use sed
:
sed "s/['\"]/\\\\&/g" <<< "abc'def',\"foo\",bar"
abc\'def\',\"foo\",bar
If you want to avoid escaping already escaped quotes then use:
sed -E "s/(^|[^\\])(['\"])/\\1\\\\\\2/g" file
Upvotes: 2