I have a line such as:
sed -i \'s/mystring/newstring/\' $target
This command will change all mystring
to newstring
.>
This is from the sed one-liners page:
OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to large input files or slow processors or hard disks), substitution will be executed more quickly if the "find" expression is specified before giving the "s/.../.../" instruction. Thus:
sed 's/foo/bar/g' filename # standard replace command sed '/foo/ s/foo/bar/g' filename # executes more quickly sed '/foo/ s//bar/g' filename # shorthand sed syntax
Speed is not the issue of the question at hand, but the syntax hints help formulating the solution:
sed -i '/searchstring/ s/mystring/1/; s/mystring/0/' $target