0

I have files that contain ;" and I need it replaced with ';"

The following sed command does not work:

sed -i "s/;"/';"/g" /root/bashy.sh

How can I do this? The solution doesn't have to be sed.

  • You should be more specific about 'does not work' - what error do you get? And what effects? – Toby Speight May 28 '15 at 17:40
1

This is a shell mistake, not a sed one - your quotes need to be quoted:

sed "s/;\"/';\"/g"

Or even

sed s/';"'/"'"';"'/g

if you don't like backslashes...

  • Thank you. How would I do it for spaces? sed -i "s/= /= '/g" – Teddy291 May 28 '15 at 17:48
1

With GNU sed:

sed -i.bak 's/;"/\x27&/g' file

POSIX sed:

sed -e "s/;\"/'&/g" < file > file.out
  • Thank you. How would I do it for spaces? sed -i "s/= /= '/g" – Teddy291 May 28 '15 at 17:48
  • @Teddy291: sed -i.bak 's/= /&\x27/g' file – cuonglm May 28 '15 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.