-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrep.txt
30 lines (24 loc) · 1.3 KB
/
grep.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# this is a /mostly/ correct interpretation of the man pages, the details on regex are hairy and depend on the grep
# version and implementation
-i case-insensitive
-v negate matches (invert result)
-e use for each pattern if you have more than one to match or negate (it ORs)
-E extended regex.
-P Perl compatible regex
-s surpress that warning about directories (and other unreadable files)
--include \*.php # only search these files. either escape the * or quote the string
# find LITERAL periond: use quotes _and_ escape it
$ grep 'foo\.txt' *
### output
-H print filename with each match (default for wildcard file patterns)
-h do NOT print filename even for multiple files, this is useful when you want to further parse the contents
-n print line number
[-A, -B, -C]# print # lines after, before, or around matching lines
-o print only the matching part of the line, useful to regex values out of a file for use in a pipeline
-m # print only the first # matching lines
-l print only the filenames, not the matching lines
# filter out empty lines for, say, -v, by using a start/end pattern ^$
$ grep -v -e foobar -e ^$
# bugs
grep will hang on named pipes/FIFO type things, and not skip them even if they are in the --exclude list. You can use
--device=skip to not process this type of file.