bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: --only-match


From: Alain Magloire
Subject: Re: --only-match
Date: Tue, 8 May 2001 12:59:50 -0400 (EDT)

Bonjour

> Hello,
> 
> I'm using GNU grep 2.5f from CVS.  I found the several options added
> such as --color, --perl-regexp.  They are very cute and useful for me,
> thanks.
> 
> Now, I want the option --only-match to produce the following result:
> 
> $ grep --only-match -P \
>    'http:(//[-\w_.]+:\d*)address@hidden&*+|\\/.,address@hidden&*+|\\/]' \
>   ~/.lynx/bookmark.html | tail -5
> http://members.home.net/ncherry/#Software
> http://www.sarion.co.jp/ml/soap/
> http://www.fujitv.co.jp/jp/meza/uranai/syumatsu.html
> http://www.extreme.indiana.edu/cat/ris/
> http://www.jaist.ac.jp/~shinoda/unp2e/
> 
> Are there any plans to introduce this (or such)?
> 
> Here is the quick and dirty patch:

hmm ... looks usefull.  Jim Meyering was bugging me about something
similar 8-) and other features like printing the lines and the regex where
things failed with -f.

I'll put this on my getting_too_long_grep_requests_queue.

Meanwhile, you could help your cause(bumping the queue) by providing
doc/grep.{1,texi} and ChangeLog entries for the patch.

My english writing skills are flaky but "--only-match" does not sound right.
Sorry I do not have any better alternative.

Thanks for the patch/comments.

-- 
au revoir, alain
----
Aussi haut que l'on soit assis, on n'est toujours assis que sur son cul !!!

> 
> --Multipart_Wed_May__9_01:31:16_2001-1
> Content-Type: application/octet-stream; type=patch
> Content-Disposition: attachment; filename="only-match.diff"
> Content-Transfer-Encoding: 7bit
> 
> Index: src/grep.c
> ===================================================================
> RCS file: /home/cvs/grep/src/grep.c,v
> retrieving revision 1.67
> diff -u -F^( -r1.67 grep.c
> --- src/grep.c        2001/03/19 00:10:44     1.67
> +++ src/grep.c        2001/05/08 16:29:11
> @@ -69,6 +69,9 @@
>  /* If nonzero, use grep_color marker.  */
>  static int color_option;
>  
> +/* If nonzero, only print the matching string.  */
> +static int only_match_option;
> +
>  /* The color string used.  The user can overwrite it using the environment
>     variable GREP_COLOR.  The default is to print red.  */
>  static const char *grep_color = "31;5";
> @@ -87,7 +90,8 @@
>    INCLUDE_OPTION,
>    EXCLUDE_OPTION,
>    EXCLUDE_FROM_OPTION,
> -  LINE_BUFFERED_OPTION
> +  LINE_BUFFERED_OPTION,
> +  ONLY_MATCH_OPTION
>  };
>  
>  /* Long options equivalences. */
> @@ -123,6 +127,7 @@
>    {"no-messages", no_argument, NULL, 's'},
>    {"null", no_argument, NULL, 'Z'},
>    {"null-data", no_argument, NULL, 'z'},
> +  {"only-match", no_argument, NULL, ONLY_MATCH_OPTION},
>    {"perl-regexp", no_argument, NULL, 'P'},
>    {"quiet", no_argument, NULL, 'q'},
>    {"recursive", no_argument, NULL, 'r'},
> @@ -508,7 +513,7 @@
>  #endif
>        print_offset_sep (pos, sep);
>      }
> -  if (color_option)
> +  if (color_option || only_match_option)
>      {
>        size_t match_size;
>        size_t match_offset;
> @@ -519,11 +524,19 @@
>         /* Avoid matching the empty line at the end of the buffer. */
>         if (b == lim)
>           break;
> -       fwrite (beg, sizeof (char), match_offset, stdout);
> -       printf ("\33[%sm", grep_color);
> -       fwrite (b, sizeof (char), match_size, stdout);
> -       fputs ("\33[00m", stdout);
> -       beg = b + match_size;
> +       if (only_match_option)
> +         {
> +           fwrite (b, sizeof (char), match_size, stdout);
> +           beg = lim - 1;
> +         }
> +       else
> +         {
> +           fwrite (beg, sizeof (char), match_offset, stdout);
> +           printf ("\33[%sm", grep_color);
> +           fwrite (b, sizeof (char), match_size, stdout);
> +           fputs ("\33[00m", stdout);
> +           beg = b + match_size;
> +         }
>       }
>      }
>    fwrite (beg, 1, lim - beg, stdout);
> @@ -1034,6 +1047,7 @@
>    -C, --context=NUM         print NUM lines of output context\n\
>    -NUM                      same as --context=NUM\n\
>        --color, --colour     use markers to distinguish the matching string\n\
> +      --only-match          only print the matching string\n\
>    -U, --binary              do not strip CR characters at EOL (MSDOS)\n\
>    -u, --unix-byte-offsets   report offsets as if CRs were not there 
> (MSDOS)\n\
>  \n\
> @@ -1492,6 +1506,10 @@
>  
>        case LINE_BUFFERED_OPTION:
>       line_buffered = 1;
> +     break;
> +
> +      case ONLY_MATCH_OPTION:
> +     only_match_option = 1;
>       break;
>  
>        case 0:
> 
> --Multipart_Wed_May__9_01:31:16_2001-1
> Content-Type: text/plain; charset=US-ASCII
> 
> 
> Regards,
> -- 
> Daiki Ueno
> 
> --Multipart_Wed_May__9_01:31:16_2001-1--
> 
> _______________________________________________
> Bug-gnu-utils mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-gnu-utils
> 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]