bash - How to use grep to find string that contain "\n" char? -
i want use powerful grep
find strings contain following sentence in matlab
source files in directory.
fprintf('error: invalid indexes!\n');
i've tried following command, shows errors.
grep -rl "fprintf(\'error: invalid indexes!\\n\');" ./
i've tried solutions presented in here, seems not work.
could please give advice?
in addition, after find matched strings, want replace them following sentence:
if(length(invalid_idx)>0) fprintf('error: invalid indexes!\n'); end
i know use following command:
grep -rl "need_to_replaced_strings" ./ | xargs sed -i 's/need_to_replaced_strings/replaced_strings/g'
i'm not sure if replaced_strings
in command above should have special considerations.
the errors follows:
try this:
$ grep -erl 'fprintf\('\''error: invalid indexes!\\n'\''\);' ./ fprintf('error: invalid indexes!\n');
use -e
option , escape inner single quotes'\''
outside single-quoted string.
or, if escape single quotes '"'"'
below:
$ grep -erl 'fprintf\('"'"'error: invalid indexes!\\n'"'"'\);' ./
Comments
Post a Comment