<p dir="ltr">I&#39;ve notice that different distros use grep/egrep based on how it&#39;s called and some always call egrep. That will fubar badly moving between environments. I&#39;ve gotten in the habit of &quot;grep for text, egrep for everything else&quot;. <br>
So &quot; what file has string foo?&quot; 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&#39;ll bet that is already an option. I think it&#39;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, &quot;DJ-Pfulio&quot; &lt;<a href="mailto:djpfulio@jdpfu.com">djpfulio@jdpfu.com</a>&gt; 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 &quot;[abc]+&quot;<br>
      &lt;nothing returned&gt;<br>
<br>
<br>
 $ ls -1 |grep &quot;[abc]&quot;<br>
 aaaa<br>
 bb<br>
 ccc<br>
<br>
<br>
 $ ls -1 |grep &quot;[abc]*&quot;<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 &quot;[abc]+&quot;<br>
 aaaa<br>
 bb<br>
 ccc<br>
<br>
Gotta know which regex engine is being used. ;)<br>
In perl, I&#39;ve used numbers after an [] group to say exactly how many of _those<br>
things_ I needed. That didn&#39;t work with grep/egrep. Don&#39;t know why, just know it<br>
didn&#39;t.<br>
<br>
 $ ls -1 |grep &quot;[abc]c&quot;<br>
 ccc<br>
# and<br>
 $ ls -1 |grep &quot;^[abc]c&quot;<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&#39;t really letters to the computer. ;(<br>
<div class="quoted-text"><br>
On 09/23/2016 09:01 AM, Charles Shapiro wrote:<br>
&gt;<br>
&gt; Ah, regex golf.  Try &#39;def.*buff.*for.*ALTPLAN&#39;  Use &quot;grep -i&quot; to ignore case.<br>
&gt; Your initial regexp used *file* regex, where &quot;*&quot; means any character any<br>
&gt; length.  In the proper formal dialects, &quot;*&quot; merely means any number of the<br>
&gt; preceding RE, and the &quot;.&quot; means any character. Hence, &quot;foo*&quot; in the shell<br>
&gt; matches &quot;fooa&quot;,&quot;foob&quot;, et cetera.  But in regex, it matches only &quot;foo&quot;, &quot;fooo&quot;,<br>
&gt; &quot;foooooo&quot;, et cetera. Watch out for quoting in the shell also; that&#39;s why I used<br>
&gt; single-quotes.  Knowing just a few REs can carry you a surprising distance.<br>
&gt;  [abc] matches the single character a,b,and c.  So &quot;[abc]+&quot; matches aaaa, bb, or<br>
&gt; ccc but not i.<br>
&gt;<br>
&gt;<br>
&gt; This worked for me on the following file:<br>
&gt;<br>
&gt; define buffer snort for ALTPLAN<br>
&gt; DEFINE BUFFER BOOF for ALTPLAN<br>
&gt; FOO<br>
&gt;<br>
&gt; !:/home/cshapiro/Mapping_<wbr>Contracts/forsythco&gt; grep -i &#39;^def.*buf.*for ALTPLAN&#39;<br>
&gt; foo.txt<br>
&gt; define buffer snort for ALTPLAN<br>
&gt; DEFINE BUFFER BOOF for ALTPLAN<br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; -- CHS<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Sep 22, 2016 at 8:35 PM, DJ-Pfulio &lt;<a href="mailto:DJPfulio@jdpfu.com">DJPfulio@jdpfu.com</a><br>
</div><div class="elided-text">&gt; &lt;mailto:<a href="mailto:DJPfulio@jdpfu.com">DJPfulio@jdpfu.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     I&#39;d use perl. Trivial to read a file, find the lines matching any<br>
&gt;     complex regex you like, back up 3 lines and print the following 14 lines.<br>
&gt;     Don&#39;t forget to handle lines that happen inside the group to be<br>
&gt;     exported. Would be good to show file:linenum:LINE so it is clear -<br>
&gt;     perhaps highlight the actual line with &lt;&lt; &gt;&gt; - idunno.<br>
&gt;<br>
&gt;     I like Leam&#39;s regex except the leading ^ and trailing $ - these things<br>
&gt;     don&#39;t need to start in col-1 or end of line. Otherwise, probably<br>
&gt;     restrictive enough to minimize unwanted output.<br>
&gt;<br>
&gt;     On 09/22/2016 07:30 PM, Leam Hall wrote:<br>
&gt;     &gt; Why not &quot;^def*buff*altplan$&quot;? Then grep v out things you don&#39;t want.<br>
&gt;     &gt;<br>
&gt;     &gt; On 09/22/16 14:46, Neal Rhodes wrote:<br>
&gt;     &gt;&gt; So, I need to look in about a bazillion source files for variants of<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt;     DEFINE BUFFER SNORT FOR ALTPLAN.<br>
&gt;     &gt;&gt;     Define Buffer Blech for AltPlan.<br>
&gt;     &gt;&gt;     Def    Buff   Blurf for AltPlan.<br>
&gt;     &gt;&gt;     Def Buff Blurf for AltPlan.<br>
&gt;     &gt;&gt;     def buff blurf for altplan.<br>
&gt;     &gt;&gt;     define buff blurf for altplan.<br>
&gt;     &gt;&gt;     define                      buffer                   blorf for<br>
&gt;     &gt;&gt; altplan.<br>
&gt;     &gt;&gt;     define  new shared buffer                   blorf for altplan.<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt; And grap 3 lines before, 10 lines afterwards, source file and  line#.<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt; I was thinking this would to it:<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt;     grep -i -B 3 -A 10 -H -n -r -f buf-grep.inp * &gt; buf.grep.out<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt; Where buf-grep.inp was<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt;     def*buff*for*ALTPLAN<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt;     def*buff*for*ARM<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt;     def*buff*for*ARMNOTE<br>
&gt;     &gt;&gt;<br>
&gt;     &gt;&gt; Alas it is not thus, and the more I study the reg exp notes the more I<br>
&gt;     &gt;&gt; see there error of my ways, and the less I see an expression that would<br>
&gt;     &gt;&gt; work.<br>
&gt;     &gt;&gt;<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>