Com esse artigo estamos dando início a uma série de pequenos artigos/textos sobre os poderes de se usar a linha de comando, explorando as funcionalidades de um shell e de alguns comandos GNU. Esse tipo de artigo foi pedido por várias pessoas e acreditamos que podem ser bem úteis, especialmente para aqueles que não leem em inglês ou gostariam de umas dicas rápidas.
O primeiro será sobre duas ferramentas bastante úteis para busca/procura: find e grep.
ll
The grep command searches one or more input files for lines containing a match to a specified pattern. By default, grep prints the matching lines.
When it finds a match in a line, it copies the line to standard output (by default)
`-c’ – numero de linhas match
`-v’, `–invert-match’ option, count non-matching lines.
- `-i’ `–ignore-case’
- `-n’
- `–line-number’
- Prefix each line of output with the line number within its input file.
- http://www.gnulamp.com/grep.html
- `-H’
- `–with-filename’
- Print the filename for each match.
- -w palavra, -r recrsivo
- http://www.gnu.org/software/grep/doc/grep_6.html#SEC6
- reg exp: http://www.gnu.org/software/grep/doc/grep_7.html#SEC7
The ‘$’ matches end-of-line.
grep -o ‘[A-Za-z0-9]*$’ data-file > out-file
– tellarin