Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] grep question


On Mon, Apr 14, 2008 at 10:16:32AM +1000, Amos Shapira wrote:
> On Sun, Apr 13, 2008 at 10:02 PM, Alex Samad <alex@xxxxxxxxxxxx> wrote:
> > On Sun, Apr 13, 2008 at 09:55:13PM +1000, Amos Shapira wrote:
> >  > On Sun, Apr 13, 2008 at 9:41 AM, Alex Samad <alex@xxxxxxxxxxxx> wrote:
> >  > >  > Try grep -Ev '^(\W*;|$)'
> >  > >  great that works, (i changed to \s* instead, also tried the [[:space:]]
> >  > >  and it worked)
> >  > >
> >  > >  I don't understand hwy i need to test for ^$, I had thought that once a
> >  > >  line test positive for ^\s*; it would be excluded ?
> >  >
> >  > Because empty lines do not match the '^\W*;' part (they don't have a
> >  > ';' in them to match the regular expression) and so grep prints them.
> >  > The '^$' part matches empty lines and so they are filtered out.
> >
> >  but the line has already been matched why is it not discarded ?
> 
> Nope. The empty lines you see in the output (without the "^$" match)

exactly, silly me assumed there were no blank lines in the original text
file.  The old addage assume makes an ass out of u and me 

> are empty lines from the original file (look them up), not lines which
> matched the ":" RE.
> 
> When you look for empty lines in the input, be aware that there could
> be lines containing only white space, which won't match "^$" (to test,
> use "cat -e" on the file) but still look empty to "the naked eye",
> maybe you want you change that RE to something like:
> "^[:space:]*(;|$)" (i.e. match lines which begin with ";" (optionally
> preceded by white space) or which contain only zero or more white
> spaces).
> 
> --Amos
> -- 
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
> 

-- 
"Let me just first tell you that I?ve never been more convinced that the decisions I made are the right decisions."

	- George W. Bush
09/12/2006
Washington, DC
said to journalists in the Oval Office (as reported by the National Review)

Attachment: signature.asc
Description: Digital signature