Difference between revisions of "grep"
Jump to navigation
Jump to search
(→Questions: an answer) |
(extracted manpage transcrip to a subpage; reference links) |
||
Line 1: | Line 1: | ||
− | + | ==Pages== | |
− | == | + | * {{l/manpage}} - the current [[manpage]] |
− | + | * [[/manpage]] - a nicely-formatted but old version of the grep manpage | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | * | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Questions== | ==Questions== | ||
* So, how do you grep for a string which contains spaces and quote characters? This is probably some standard feature of Linux Shell syntax which everyone knows, but I don't, and that's why this page needs examples. | * So, how do you grep for a string which contains spaces and quote characters? This is probably some standard feature of Linux Shell syntax which everyone knows, but I don't, and that's why this page needs examples. | ||
Line 185: | Line 13: | ||
==Notes== | ==Notes== | ||
If ''file'' is specified using wildcards (e.g. *.log or *.*), apparently the command-line parser expands this into a listing of all matching files before passing it to grep. This unfortunately can lead to the error "bash: /bin/grep: Argument list too long". Putting a backslash before the wildcard will prevent the parser from expanding it before passing to grep, but grep doesn't seem to have any wildcard-handling abilities. So as far as I can tell, there is no way to grep a really large directory (the one I'm looking at has 5014 files). | If ''file'' is specified using wildcards (e.g. *.log or *.*), apparently the command-line parser expands this into a listing of all matching files before passing it to grep. This unfortunately can lead to the error "bash: /bin/grep: Argument list too long". Putting a backslash before the wildcard will prevent the parser from expanding it before passing to grep, but grep doesn't seem to have any wildcard-handling abilities. So as far as I can tell, there is no way to grep a really large directory (the one I'm looking at has 5014 files). | ||
− | + | ==Links== | |
− | == | + | * [http://www.gnu.org/software/grep/manual/ official documentation]: more current than the manpage |
− | * | + | * {{wikipedia}} |
Revision as of 16:11, 17 May 2015
Pages
Questions
- So, how do you grep for a string which contains spaces and quote characters? This is probably some standard feature of Linux Shell syntax which everyone knows, but I don't, and that's why this page needs examples.
- Likewise, how do you search a group of files? Using "*.*" for FILE doesn't seem to work, and leaving the FILE argument blank tells grep to expect input from STDIN.
- A: apparently "*" by itself; see examples below
Examples
- grep text_to_find *.log
- find text_to_find by checking all the logfiles in the current folder
- grep -r text_to_find *
- find text_to_find by checking all files in the current folder or under it
Notes
If file is specified using wildcards (e.g. *.log or *.*), apparently the command-line parser expands this into a listing of all matching files before passing it to grep. This unfortunately can lead to the error "bash: /bin/grep: Argument list too long". Putting a backslash before the wildcard will prevent the parser from expanding it before passing to grep, but grep doesn't seem to have any wildcard-handling abilities. So as far as I can tell, there is no way to grep a really large directory (the one I'm looking at has 5014 files).
Links
- official documentation: more current than the manpage
- Wikipedia