I want to use the powerful
grep to find those strings that contain the following sentence in the
MATLAB source files in the directory.
fprintf('Error: invalid indexes!\n');
I've tried the following command, but it shows errors.
grep -rl "fprintf(\'Error: invalid indexes!\\n\');" ./
I've tried the solutions presented in here, but it seems to not work.
Could you please give some advice?
In addition, after find those matched strings, I want to replace them into the following sentence:
if(length(invalid_idx)>0) fprintf('Error: invalid indexes!\n'); end
I know we could use the following command:
grep -rl "need_to_replaced_strings" ./ | xargs sed -i 's/need_to_replaced_strings/replaced_strings/g'
I'm not sure if the
replaced_strings in the command above should have some special considerations.
The errors is as follows: