grep: input file 'X' is also the output
It is not possible to use the same file as input and output for grep
.
You may consider the following alternatives:
temporary file
grep pattern file > tmp_file mv tmp_file file
sed
sed -i -n '/pattern/p' file
put whole file in the variable (not bright idea for large files)
x=$(cat file); echo "$x" | grep pattern > file
You can use the --exclude
field in your grep
command like so:
grep --exclude=myfile -Eron r"%}(.*){%" > myfile