I want to replace a specific instruction containing brackets with another instruction recursively in all the files.
For example,
mov r1, [r1, r2]
with
sub [r8, r9], r10
When I use
sed -i.bak "s/mov r1, [r1, r2]/sub [r8, r9], r10/g" file.S
it doesn't work.
How can I do that?
Escaping the brackets -- [ ] -- in sed's substitute command will process your file the way you expect it to. Here is your command rewritten with the brackets escaped:
Two things.
Thus:
While working out the correct script you can just skip the inline editing, maybe. Like so:
Try with escaped brackets
's/mov r1, \[r1, r2\]/sub \[r8, r9\], r10/g'
.