0

i have a file test.txt with data init=6'b000000; and i want to replace it with init=6'b110111; by using vim script in a bash file. I'm getting error

I'm using following command:

vim -c '%s/init=6'b000000;/init=6'b110111;/g | write | quit' test.txt

this works perfectly in vim, not in bash .

Inian
  • 80,270
  • 14
  • 142
  • 161

1 Answers1

2

This has nothing to do with Vim, you cannot embed a single quote inside a pair of other single quotes. The shell parses the command line arguments before passing them to the invoked command and it just cannot deal with the inner single quote in the way you have defined.

The literal single quote inside need to be preserved before passing to the command. So use double quote and escape the inner quote

vim -c "%s/init=6\'b000000;/init=6\'b110111;/g | write | quit" file

or use the single quote, but include a multi-level double quote inside

vim -c '%s/init=6'"\'"'b000000;/init=6'"\'"'b110111;/g | write | quit' file
Inian
  • 80,270
  • 14
  • 142
  • 161