Redirigir grep a un archivo no funciona

Redirigir grep a un archivo no funciona

Estoy haciendo un grep recursivo con el siguiente comando:

grep -r "load" . > tmp.txt

Sin embargo, cuando presiono Enter, el comando no se ejecuta y bash está esperando más entradas. Mi sistema operativo es Ubuntu 12.04.

Revisé las siguientes dos respuestas pero no pudieron resolver mi problema.

¿Por qué grep no funciona con la redirección?

¿Cómo redirijo la salida de tailf & grep a un archivo?

Respuesta1

También uso Ubuntu 12.04 y aparece este error:

$ grep -r 'test' . > tmp.txt
grep: input file `./tmp.txt' is also the output

Debido a que la redirección se expandirá primero, tmp.txtse crea en el directorio actual antes de grepejecutarse, lo que genera un error.

Si cambio tmp.txta otra ruta, como /tmp/tmp.txt, entonces funciona normalmente.

Mi grepversion:

$ grep --version
grep (GNU grep) 2.10
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

información relacionada