Cómo invertir una expresión grep
La siguiente expresión grep lista correctamente todos los .exe y .archivos html en el directorio y subdirectorios actuales.
ls -R |grep -E .*[\.exe]$\|.*[\.html]$
Cómo invierto este resultado para enumerar los que no son a .html o .exe en su lugar. (Es decir, !=
.)
171
Author: Peter Mortensen, 2010-12-07
5 answers
Utilice la opción de línea de comandos -v
o --invert-match
,
ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$
253
Author: Eric Fortis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-30 15:47:38
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-30 15:47:38
grep -v
O
grep --invert-match
También puedes hacer lo mismo usando find
:
find . -type f \( -iname "*" ! -iname ".exe" ! -iname ".html"\)
Más información aquí .
70
Author: darioo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-07 05:31:46
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-07 05:31:46
Agregue la opción -v
a su comando grep
para invertir los resultados.
28
Author: Rob Sobers,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-07 05:35:15
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-07 05:35:15
grep "subscription" | grep -v "spec"
6
Author: miukki,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-02 08:46:49
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-02 08:46:49
Como se indica varias veces, la inversión se logra mediante la opción -v
a grep
. Permítanme añadir la (esperemos que divertido) nota que usted podría haber descubierto esto por sí mismo leyendo el grep
texto de ayuda:
grep --help | grep invert
- v, inver invert-match seleccionar líneas no coincidentes
0
Author: jmd_dk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-13 05:04:47
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-13 05:04:47