3 ms·
Thanks for providing these! I do think these become unwieldily when you want something like "X and Y and not Z and (A or B)" right? Not only that, I think impl
by davidatbu 5y ago
Thanks for providing these! I do think these become unwieldily when you want something like "X and Y and not Z and (A or B)" right?
Not only that, I think implementing "or" logic would be quite convoluted by itself right?
- jolmg 5y agoNot really. For regexes, "or" is particularly simple, since you can just use `|` in the regex. I would do this: $ grep -l X files/* | xargs grep -l Y | xargs grep -L Z | xargs grep -El 'A|B' Here's an awk solution that avoids `|` in the regex: $ find files -type f -exec awk '/X/{x=1} /Y/{y=1} /Z/{z=1} /A/{a=1} /B/{b=1} END { if (x && y && ! z && (a || b)) print FILENAME }' {} \; Depending on what your files look like, joining the lines in the files may also be an option: $ find files -type f -exec awk 'BEGIN{a=FILENAME}{a=a" "$0}END{print a}' {} \; | awk '/X/ && /Y/ && ! /Z/ && (/A/ || /B/) { print $1 }' I imagine being able to write expressions like the one on this last one is what you're looking for. All this isn't to say that there isn't space for a new tool. Certainly a tool can be made that allows expressing these more succinctly if you really want it.
- davidatbu 5y agoThanks for all this! I really like the first `grep` solution. Dunno how I didn't think of that myself ...