-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Multiple, Newline-Separated Patterns #646
base: dev
Are you sure you want to change the base?
Conversation
(Personally, I think this is a more useful fix than #522) |
Thanks for this, Dabe. Interesting idea that I think is worth talking about. The idea of multiple regexes is not a new one. If we do adopt it, it will go into ack3, not ack2. ack2 is not getting any new development. ack3 is getting ready for its first alpha in the next week or two. If we do add this, it would be a great thing to have on the "new in ack 3!" features list. Some thoughts, in no particular order:
|
Ack already has ability to do multiple patterns with We have tried to maintain some degree of plug-compatibility with (f)grep, but since the RE language is different, it can't be exact. An ability to read a bunch of -wQ words from a file would not be bad.
|
I didn't even realize there was an ack3. Mea culpa I'm all for a more elegant solution than But I haven't looked to see what, e.g., GNU grep does to maximize efficiency. In terms of measuring speed, though, it's kind of tough, since currently there's NO way to include multiple regexes. (So does that make this "infinitely" faster? «wink») |
I haven't really announced it, and there's not really a central place to announce it. :-/ |
@DabeDotCom What prompted you to want this bit of functionality? |
Yup, I acknowledged that. But this is just gross, IMHO:
AND it opens you up to injection bugs:
|
@petdance I wanted to be able to do:
to get a list of all files, sorted by date, highlighting the ones that matched. (Admittedly, there are still some pathological cases — like if a filename contains a newline, e.g. But POSIX grep would fail that, too...) |
We have tried to maintain some degree of plug-compatibility with While not supporting this GNUism may violate least-surprise for folks who discovered this quirk in GNU Encouraging embedding newlines in cmd line arguments doesn't make me happy either. If anything, if we wish to provide a (However, an ability to read a bunch of -
ack /etc --match "`/bin/ls /home/ | tr '\n' '|' | sed -e 's/|$//'`"
That isn't ack doing that, that's the calling script trusting its input.
Nice touch, i like that . |
@n1vux Actually, it wouldn't. From
There, I WANT the alternation...
I had drafted a different issue for that, too! «grin» POSIX grep allows for multiple
Yet another issue I started to open was to include This would let me use process substitution to do:
|
That one I'm much less keen to pursue. Aside: If you haven't looked at |
ls -ltr | ack --passthrough "`grep -l SOME_TAG *`"
Is there a reason Gnu Grep doesn't work here? It has got highlighting now. Does it lack a (On my system, Ok, we like compound queries with I know I can list just the matching ones in date order with full ack -l $USER /etc 2>/dev/null | xargs ls -lart (use the 0 options if afflicted with spaces in path/names) I will take this as a challenge to consider alternative solutions for Ack3 Cookbook that are less ugly than the (Although if GnuGrep or some other tool can do some "it" better than Ack, we are willing in the Cookbook section to recommend Gnu Grep for doing "it".) |
I love process substitution filehandles in recent |
Ironically, ignoring (And BTW — I'm not trying to stir the pot, here! I can't even begin to express how appreciative I am for you guys' hard work!! I'm just one of those pesky users who's always asking for more features than I'm capable of actually implementing myself... «sigh») |
Correct. (And as a very trivial nit: ack spells it |
Amen. RIP Jon, and his acolyte my mentor MAP also. so to summarize , No total solutions from the beyondgrep.com Other Tools tab spotted in a quick scan:
Not that i'm convinced that this is a usecase that must be possible without writing some real code, but it is so tantalizingly close to what we can do with just ack/grep/ls/bash while being a little outlandish that as a Cookbook challenge i'm game to explore how close i can get! Thanks for the example. I expect i can do it somewhat less inelegantly than your sed, tr bad example (that sort of ugly exactly is why i learned AWK and then Perl4+5 when i first got on Unix back in %DECADE%CENSORED%), it'll be a lovely bit of chrome for the Ack3 cookbook. Stay tuned, I'll try to post my improvement back here but it should be in Ack3 docs when released. |
The best I've got so far is ....
ack /etc --match "`/bin/ls /home/ | tr '\n' '|' | sed -e 's/|$//'`"
ack /etc --match $(/bin/ls /home/ | perl -E '@u=<>; chomp for @u; say join q(|), @u' )
|
Per POSIX 1003.1:
So, for example, you could do:
Now you can do the same with
ack
:This is especially handy with command substitution [backticks], as it means you don't have to manually perform any
alice|bob|carol
shenanigans; the alternation is automatically performed for you: