I’m using pcregrep to search for a multiline pattern, and I only want pcregrep to search through files with specific file extensions, i.e.
pcregrep -Mrl --include=*.sv -e '<my_multi-line_pattern>' /path/to/search
However, this throws an error: pcregrep: Error in 'include' regex at offset 0: nothing to repeat.
I’ve tried escaping & double-escaping the * to no avail. This syntax seems to work just fine for grep
grep -rl --include=*.sv '<my_single-line_pattern>' /path/to/search
Any help or hints greatly appreciated.
EDIT: Example multi-line pattern: '(?s)^salu.*.opa_i('
should match
alu u_alu(
...
.opa_i(opa),
.opb_i(opb),
...
)
Advertisement
Answer
Here’s what pcregrep’s docs say about --include (emphasis mine):
--include=patternIf any--includepatterns are specified, the only files that are processed are those that match one of the patterns (and do not match an--excludepattern). This option does not affect directories, but it applies to all files, whether listed on the command line, obtained from--file-list, or by scanning a directory. The pattern is a PCRE regular expression, and is matched against the final component of the file name, not the entire path. The-F,-w, and-xoptions do not apply to this pattern. The option may be given any number of times. If a file name matches both an –-includeand an--excludepattern, it is excluded. There is no short form for this option.
And a * at the start of a regex is of course not valid.
Now you can make sense of the error message 🙂
Solution: --include='.*.sv$' or just --include='.sv$'