Dgrep [ options ] pattern [ input-file.. ]
Dgrep [ options ] [ -e pattern ].. [ -f pattern-file ].. [ input-file.. ]
Dgrep selects records by a pattern matching using regular expressions. The pattern is taken from the first operand (first form of the synopsis above), or from the -e options, and/or from the file[s] given with -f options (second form). If there is no -e or -f options, then the first operand is the pattern, and following operands are the input-files. If there is at least one -e or -f option, patterns are taken from it, and all operands are the input-files.
When there are more than one patterns (-e and -f options are repeatable), the records which match to the all patterns are selected (i.e., conditions are combined by AND).
For the regular expression, see the manual of Dintro.
There are two modes of pattern matching. One is single line matching which is the default, and the other is multiple line matching introduced by the -m option.
In the case of the single line matching, each pattern is matched with the fields of the record. Each field (including the field name, COLON and the value) is regarded as a string, and the pattern is matched with this string (i.e. "^" and "$" means the beginning and the end of a field). When a pattern matches at least one field of the record, it matches to the record. Lines read in from the -f pattern-file are taken as the separate patterns.
In the case of the multiple line matching, each pattern is matched with the whole record, including the new line characters separating the fields. Regular expression "^" means the beginning of the record (i.e., top of the field name part of the first field), and "$" means the end of the record (after the newline character terminating the last field). New line characters in the pattern are handled as normal characters, and match to the new line characters between fields.
In the multiple line matching mode, lines read in from a pattern-file make a pattern as a whole (i.e. including new line characters). This is useful because it may be difficult to give new line characters from your shell.
Selects records which have "foo" somewhere in the record:
Dgrep foo
Selects records which have "foo" and "bar":
Dgrep -e foo -e bar
Selects records which have "foo" and "bar" in this order:
Dgrep -m "foo.*bar"
Select records of which field order is not "a", "b", "c":
Dgrep -vm -f foo
File "foo" conains:
^a:[^
]*
b:[^
]*
c:[^
] $
See the manual of D_msg.
MIYAZAWA Akira