[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch #7786] Support for multiple fixed multiline pattern matching
From: |
Jiyong Jang |
Subject: |
[patch #7786] Support for multiple fixed multiline pattern matching |
Date: |
Mon, 28 May 2012 18:28:38 +0000 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5 |
URL:
<http://savannah.gnu.org/patch/?7786>
Summary: Support for multiple fixed multiline pattern
matching
Project: grep
Submitted by: jiyongj
Submitted on: Mon 28 May 2012 06:28:37 PM GMT
Category: None
Priority: 5 - Normal
Status: None
Privacy: Public
Assigned to: None
Originator Email:
Open/Closed: Open
Discussion Lock: Any
_______________________________________________________
Details:
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
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Mon 28 May 2012 06:28:37 PM GMT Name: grep-fixed-multiline.patch Size:
5kB By: jiyongj
<http://savannah.gnu.org/patch/download.php?file_id=25947>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/patch/?7786>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [patch #7786] Support for multiple fixed multiline pattern matching,
Jiyong Jang <=