patchgrep - Patches: patch #6111, Shell script that produces a...


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

patch #6111: Shell script that produces a pipeline of greps

Submitted by:  None
Submitted on:  Mon 23 Jul 2007 01:06:42 PM UTC  
Category:  None Priority:  5 - Normal
Status:  Wont Do Privacy:  Public
Assigned to:  Stepan Kasal <kasal> Originator Email:  -email is unavailable-
Open/Closed:  Closed

Mon 23 Jul 2007 01:39:36 PM UTC, comment #1: 

  with the description:

> comma stands for logical or, minus for logical not, and everything else is and'ed

I would interpret "image,picture -gtk,gnome" as
   image OR (picture AND NOT gtk) OR gnome
because unary operator usually has the highest priority, and AND usually has higher priority than OR.
And I would expect the script would interpret parentheses as well.

But I think it is more natural to use awk for such a task, instead of several processes.  For example, the above example can be implemented with GNU awk this way:

$ apt-cache search view |
        (/image/ || /picture/) && !(/gtk/ || /gnome/)'

As you see, you can use the full power of logical expressions.

Or, if portability to any POSIX-conformant awk implementation were needed:

$ apt-cache search view |
  gawk '{l=tolower($0)};
        (l~/image/ || l~/picture/) && !(l~/gtk/ || l~/gnome/)'

To conclude, I do not think your script is suitable for inclusion to the GNU grep distribution.

In any case, thank you for your suggestion!

Have a nice day,
    Stepan Kasal

Stepan Kasal <kasal>
Project MemberIn charge of this item.
Mon 23 Jul 2007 01:06:42 PM UTC, original submission:  

I've written a shell script, pgrep, that accepts combinations of patterns (using logical and/or/not operators) and produces the relevant pipeline of greps. To exemplify,

$ apt-cache search view | pgrep image,picture -gtk,gnome

will expand to

$ apt-cache search view | grep 'image
 picture' | grep -v 'gtk

(in pgrep, comma stands for logical or, minus for logical not, and everything else is and'ed)

The script is fairly trivial but does save a lot of typing. If there's enought interest, I could spend some time to improve it (eg, allow the user to pass switches to the pipeline's greps).

ps. pgrep is actually the name of another utility, feel free to suggest another name




Attached Files
file #13440:  pgrep added by None (978B - application/x-shellscript)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by kasal (Posted a comment)

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

    Only logged-in users can vote.




    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-07-23 kasal StatusNone => Wont Do
        Assigned toNone => kasal
        Open/ClosedOpen => Closed
    2007-07-23 None Attached File- => Added pgrep, #13440

    Back to the top

    Powered by Savane 3.6