grep - Patches: patch #7786, Support for multiple fixed...
You are not allowed to post comments on this tracker with your current authentication level.
patch #7786: Support for multiple fixed multiline pattern matching
Submitter: | Jiyong Jang <jiyongj> | ||
Submitted: | Mon 28 May 2012 06:28:37 PM UTC | ||
Category: | None | Priority: | 5 - Normal |
Status: | None | Privacy: | Public |
Assigned to: | None | Open/Closed: | Open |
Attached Files
Depends on the following items: None found
Items that depend on this one: None found
Carbon-Copy List
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follows 1 latest change.
Date | Changed by | Updated Field | Previous Value | => | Replaced by |
---|---|---|---|---|---|
2012-05-28 | jiyongj | Attached File | - | Added grep-fixed-multiline.patch, #25947 |
Powered by Savane 3.13-758e.
Corresponding source code
Attached is a patch that adds a new option (-J) to support multiple fixed multiline pattern matching. We couldn't figure out how to search a fixed multiline pattern using grep, so we've added this option. Please let us know if we're missing something. :) This was originally for our research project, but we thought that this option might be also useful to others.
One way to grep a multiline pattern is to use -z option like "grep -GHnz <pattern> <file>" where <pattern> is "line1.line2.line3". Some small problems with this method would be a) -n option becomes meaningless because it would always return line #1, b) basic regex matching (-G option, default) would be slower than fixed string matching (-F option), and c) it would print whole file content instead of only matching lines if there's any match.
So, we've added a new option to extend grep's fast fixed string matching method for multiline string search. Our patch is quite straightforward.
*Usage:
$ ./grep -JHn "`echo -e "/* The color strings used for matched text.\n The user can overwrite them using the deprecated\n environment variable GREP_COLOR or the new GREP_COLORS."`" main.c
main.c:130:/* The color strings used for matched text.
The user can overwrite them using the deprecated
environment variable GREP_COLOR or the new GREP_COLORS. */
Or for multiple fixed multiline strings,
$ ./grep -JHn -f multi.txt main.c
main.c:130:/* The color strings used for matched text.
The user can overwrite them using the deprecated
environment variable GREP_COLOR or the new GREP_COLORS. */
static const char selected_match_color = "01;31"; / bold red */
static const char context_match_color = "01;31"; / bold red */
main.c:136:/* Other colors. Defaults look damn good. */
static const char filename_color = "35"; / magenta */
static const char line_num_color = "32"; / green */
static const char byte_num_color = "32"; / green */
static const char sep_color = "36"; / cyan */
static const char selected_line_color = ""; / default color pair */
static const char context_line_color = ""; / default color pair */
where "multi.txt" has
/* The color strings used for matched text.
The user can overwrite them using the deprecated
environment variable GREP_COLOR or the new GREP_COLORS. */
static const char selected_match_color = "01;31"; / bold red */
static const char context_match_color = "01;31"; / bold red */
^@/* Other colors. Defaults look damn good. */
static const char filename_color = "35"; / magenta */
static const char line_num_color = "32"; / green */
static const char byte_num_color = "32"; / green */
static const char sep_color = "36"; / cyan */
static const char selected_line_color = ""; / default color pair */
static const char context_line_color = ""; / default color pair */
^@ denotes NUL character for separating multiline patterns. In other words, line 1-5 is the 1st multiline pattern that matches with main.c line #130, and line 6-12 is the 2nd multiline pattern that matches with main.c line #136.
Best,
Jiyong Jang & Maverick Woo