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

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

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

Hi,
  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 |
  gawk 'BEGIN{IGNORECASE=1};
        (/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>
Group Member
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
 gnome'

(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

Thanks,
Serafeim

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

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)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    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.13-d3ae.
    Corresponding source code