PCRE2Project / pcre2

PCRE2 development is now based here.
Other
921 stars 194 forks source link

Please add --group-separator to pcre2grep(1) #316

Closed alejandro-colomar closed 12 months ago

alejandro-colomar commented 1 year ago

From GNU grep(1):

     --group-separator=SEP
            When  -A,  -B,  or  -C are in use, print SEP instead of --
            between groups of lines.

     --no-group-separator
            When -A, -B, or -C are in use, do not  print  a  separator
            between groups of lines.

In pcre2grep(1) there's

     ‐‐om‐separator=text
               Specify a separating string for multiple occurrences of
               ‐o.  The default is an empty string. Separating strings
               are never coloured.

but there's no way to tweak the separator between matches in -A, -B, or -C mode.

zherczeg commented 1 year ago

Note: pcre2grep is more of a demo program, not a grep replacement. Adding features there is not a priority, so we cannot promise anything.

PhilipHazel commented 1 year ago

... but I will take a look at this soon because it doesn't sound to be too much work.

alejandro-colomar commented 1 year ago

On Wed, Nov 15, 2023 at 02:21:55AM -0800, Zoltan Herczeg wrote:

Note: pcre2grep is more of a demo program, not a grep replacement. Adding features there is not a priority, so we cannot promise anything.

Heh! You may be interested in learning that I've abused your demo program to some useful extremes: :)

https://www.alejandro-colomar.es/src/alx/alx/grepc.git https://www.alejandro-colomar.es/src/alx/alx/grepc.git/tree/bin/grepc

That's a program resembing grep(1), but instead of finding text, it finds C code. It is basically a wrapper around pcre2grep(1), with some quite complex regexes. Below go some examples of use.

Cheers, Alex

$ grepc MAX /usr/include/
/usr/include/x86_64-linux-gnu/sys/param.h:#define MAX(a,b) (((a)>(b))?(a):(b))
$ grepc -C2 MAX /usr/include/
/usr/include/x86_64-linux-gnu/sys/param.h-/* Macros for min/max.  */
/usr/include/x86_64-linux-gnu/sys/param.h-#define MIN(a,b) (((a)<(b))?(a):(b))
/usr/include/x86_64-linux-gnu/sys/param.h:#define MAX(a,b) (((a)>(b))?(a):(b))
/usr/include/x86_64-linux-gnu/sys/param.h-
/usr/include/x86_64-linux-gnu/sys/param.h-
$ grepc is_valid_user_name /home/alx/src/shadow/shadow/master/
/home/alx/src/shadow/shadow/master/lib/chkname.h:extern bool is_valid_user_name (const char *name);
/home/alx/src/shadow/shadow/master/lib/chkname.c:bool is_valid_user_name (const char *name)
{
    /*
     * User names length are limited by the kernel
     */
    if (strlen (name) > sysconf(_SC_LOGIN_NAME_MAX)) {
        return false;
    }

    return is_valid_name (name);
}
$ </usr/include/x86_64-linux-gnu/sys/param.h grepc -n roundup
(standard input):93:# define roundup(x, y)  (__builtin_constant_p (y) && powerof2 (y)             \
                         ? (((x) + (y) - 1) & ~((y) - 1))                     \
                         : ((((x) + ((y) - 1)) / (y)) * (y)))
(standard input):97:# define roundup(x, y)  ((((x) + ((y) - 1)) / (y)) * (y))

-- Reply to this email directly or view it on GitHub: https://github.com/PCRE2Project/pcre2/issues/316#issuecomment-1812178486 You are receiving this because you authored the thread.

Message ID: @.***>

-- https://www.alejandro-colomar.es/

PhilipHazel commented 1 year ago

I have implemented this in HEAD.

alejandro-colomar commented 1 year ago

Thanks! I'll be waiting for your next release. :)

PhilipHazel commented 12 months ago

Closed as completed.