<p dir="ltr">I've notice that different distros use grep/egrep based on how it's called and some always call egrep. That will fubar badly moving between environments. I've gotten in the habit of "grep for text, egrep for everything else". <br>
So " what file has string foo?" is a grep for me. I call egrep explicitly for regex.</p>
<p dir="ltr">I would love to see gnu remove regex capability from simple, old grep completely. Nothing but exact string matching. Then all regex usage is in egrep. Sort of baby grep vs grown up grep. Hmm. Maybe an sgrep version- simple grep or string grep with the only option being to display substring matches and limit the number of characters to drop from the string for a match.</p>
<p dir="ltr">If I dig in man grep, er, info (damn!), I'll bet that is already an option. I think it's possible to brew coffee using grep, sed awk and emacs.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Sep 25, 2016 9:15 AM, "DJ-Pfulio" <<a href="mailto:djpfulio@jdpfu.com">djpfulio@jdpfu.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Good explanation Charles, but something looks funny. I created some files to test:<br>
<br>
$ touch aaaa bb ccc i<br>
<br>
# The tried the regex:<br>
$ ls -1 |grep "[abc]+"<br>
<nothing returned><br>
<br>
<br>
$ ls -1 |grep "[abc]"<br>
aaaa<br>
bb<br>
ccc<br>
<br>
<br>
$ ls -1 |grep "[abc]*"<br>
aaaa<br>
bb<br>
ccc<br>
i<br>
<br>
# But if we used egrep (or grep -E if you like)<br>
$ ls -1 |egrep "[abc]+"<br>
aaaa<br>
bb<br>
ccc<br>
<br>
Gotta know which regex engine is being used. ;)<br>
In perl, I've used numbers after an [] group to say exactly how many of _those<br>
things_ I needed. That didn't work with grep/egrep. Don't know why, just know it<br>
didn't.<br>
<br>
$ ls -1 |grep "[abc]c"<br>
ccc<br>
# and<br>
$ ls -1 |grep "^[abc]c"<br>
ccc<br>
<br>
Should also mention that piping ls output into a grep is just to avoid bash<br>
globbing so grep is really used. That ls option is a -1 (one), not l (el).<br>
<br>
For a few years, I had to create some very nast regex to match patterns in govt<br>
documents ... so we could hyperlink the ToC and Index entries into the document<br>
at the correct page/paragraph. Nothing like experience to teach. About 200 docs<br>
per flight, so lots of variability. Adobe Type 3 fonts really screwed with our<br>
regexes since they aren't really letters to the computer. ;(<br>
<div class="quoted-text"><br>
On 09/23/2016 09:01 AM, Charles Shapiro wrote:<br>
><br>
> Ah, regex golf. Try 'def.*buff.*for.*ALTPLAN' Use "grep -i" to ignore case.<br>
> Your initial regexp used *file* regex, where "*" means any character any<br>
> length. In the proper formal dialects, "*" merely means any number of the<br>
> preceding RE, and the "." means any character. Hence, "foo*" in the shell<br>
> matches "fooa","foob", et cetera. But in regex, it matches only "foo", "fooo",<br>
> "foooooo", et cetera. Watch out for quoting in the shell also; that's why I used<br>
> single-quotes. Knowing just a few REs can carry you a surprising distance.<br>
> [abc] matches the single character a,b,and c. So "[abc]+" matches aaaa, bb, or<br>
> ccc but not i.<br>
><br>
><br>
> This worked for me on the following file:<br>
><br>
> define buffer snort for ALTPLAN<br>
> DEFINE BUFFER BOOF for ALTPLAN<br>
> FOO<br>
><br>
> !:/home/cshapiro/Mapping_<wbr>Contracts/forsythco> grep -i '^def.*buf.*for ALTPLAN'<br>
> foo.txt<br>
> define buffer snort for ALTPLAN<br>
> DEFINE BUFFER BOOF for ALTPLAN<br>
><br>
> For extra fnu, try the regex golf site ( <a href="http://www.regex.alf.nu/" rel="noreferrer" target="_blank">http://www.regex.alf.nu/</a> ).<br>
><br>
> -- CHS<br>
><br>
><br>
> On Thu, Sep 22, 2016 at 8:35 PM, DJ-Pfulio <<a href="mailto:DJPfulio@jdpfu.com">DJPfulio@jdpfu.com</a><br>
</div><div class="elided-text">> <mailto:<a href="mailto:DJPfulio@jdpfu.com">DJPfulio@jdpfu.com</a>>> wrote:<br>
><br>
> I'd use perl. Trivial to read a file, find the lines matching any<br>
> complex regex you like, back up 3 lines and print the following 14 lines.<br>
> Don't forget to handle lines that happen inside the group to be<br>
> exported. Would be good to show file:linenum:LINE so it is clear -<br>
> perhaps highlight the actual line with << >> - idunno.<br>
><br>
> I like Leam's regex except the leading ^ and trailing $ - these things<br>
> don't need to start in col-1 or end of line. Otherwise, probably<br>
> restrictive enough to minimize unwanted output.<br>
><br>
> On 09/22/2016 07:30 PM, Leam Hall wrote:<br>
> > Why not "^def*buff*altplan$"? Then grep v out things you don't want.<br>
> ><br>
> > On 09/22/16 14:46, Neal Rhodes wrote:<br>
> >> So, I need to look in about a bazillion source files for variants of<br>
> >><br>
> >> DEFINE BUFFER SNORT FOR ALTPLAN.<br>
> >> Define Buffer Blech for AltPlan.<br>
> >> Def Buff Blurf for AltPlan.<br>
> >> Def Buff Blurf for AltPlan.<br>
> >> def buff blurf for altplan.<br>
> >> define buff blurf for altplan.<br>
> >> define buffer blorf for<br>
> >> altplan.<br>
> >> define new shared buffer blorf for altplan.<br>
> >><br>
> >> And grap 3 lines before, 10 lines afterwards, source file and line#.<br>
> >><br>
> >> I was thinking this would to it:<br>
> >><br>
> >> grep -i -B 3 -A 10 -H -n -r -f buf-grep.inp * > buf.grep.out<br>
> >><br>
> >> Where buf-grep.inp was<br>
> >><br>
> >> def*buff*for*ALTPLAN<br>
> >><br>
> >> def*buff*for*ARM<br>
> >><br>
> >> def*buff*for*ARMNOTE<br>
> >><br>
> >> Alas it is not thus, and the more I study the reg exp notes the more I<br>
> >> see there error of my ways, and the less I see an expression that would<br>
> >> work.<br>
> >><br>
<br>
______________________________<wbr>_________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo</a><br>
</div></blockquote></div><br></div>