patchgrep - Patches: patch #7786, Support for multiple fixed...

 
 

You are not allowed to post comments on this tracker with your current authentification level.

patch #7786: Support for multiple fixed multiline pattern matching

Submitted by:  Jiyong Jang <jiyongj>
Submitted on:  Mon 28 May 2012 06:28:37 PM UTC  
 
Category: NonePriority: 5 - Normal
Status: NonePrivacy: Public
Assigned to: NoneOpen/Closed: Open

Mon 28 May 2012 06:28:37 PM UTC, original submission:

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

Jiyong Jang <jiyongj>

 

Attached Files
file #25947:  grep-fixed-multiline.patch added by jiyongj (5kB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jiyongj (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 28 May 2012 06:28:37 PM UTCjiyongjAttached File-=>Added grep-fixed-multiline.patch, #25947

    Back to the top


    Powered by Savane 3.1-cleanup