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.

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

2 Answers 2

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...

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

With GNU sed:

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

POSIX sed:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .