SLUG Mailing List Archives
Re: [SLUG] grep question
- To: slug@xxxxxxxxxxx
- Subject: Re: [SLUG] grep question
- From: "Amos Shapira" <amos.shapira@xxxxxxxxx>
- Date: Mon, 14 Apr 2008 10:16:32 +1000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=6uFZ68e6VsUAnwnFCrjaEMSCppO3sPit83uFwvLvBGs=; b=wDhLhg+FsJMH9nV8yPEtUm6zx8heAU81Cud21VE5O+mvIuizAvCFEQAk5XAoto/wiD5WqgHgvy8CCufesTsB0Akio9O+oQwwek6lp8nDcrrQgJPTpZ8IGTi/evVqsdbjAFX3HlAaWZvIRB+pRlY0N++kOjhbCNoQmI+yp4K+ioo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=WTp+SX5LqKg/vtCsc3LEsx5qCl4XYx1tfjZhI+HjPTtJrzOqXfQXtGFWPLVQdUPXK9HJ3UQakwochaFn4qX9jPTNDr+6ySoPOmXaQgrpw/MG86L35pPzkwIjL/JcpL2ek2cZ2deB8dWWNGiaKZAA4iATTXhG1v4OiSDIQTQWCac=
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)
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