I use ubuntu 14.4
, and been attempting to redirect the output of grep
command to a file, but I keep getting this error:
grep: input file 'X' is also the output
I run the following command:
grep -E -r -o -n r"%}(.*){%" > myfile
As the error states, it seems that somehow it's interpreting the input and output as same name/obj. I searched but couldn't find what exactly is the problem?!
grep pattern file > file
then it doesn't work. You cannot use the same file as input and output for grep. – jimmij Oct 25 '14 at 21:29bash: ../f.txt: Permission denied
– Mazdak Oct 25 '14 at 21:37grep -E -r -o -n "%}(.*){%" >> /home/user_name/Desktop/a.txt
– Mazdak Oct 25 '14 at 21:43grep
in commandgrep pattern file > file
sees already empty file, so has nothing as input. However if you use>>
instead of>
then the file is not empty, but grep throws error anyhow as it may lead to recursive processing the same line (pattern) over and over again. – jimmij Oct 25 '14 at 22:22