Stephen Gran on 10 Nov 2003 22:45:02 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] regexp assistance please


On Mon, Nov 10, 2003 at 10:21:32PM -0500, Michael C. Toren said:
> On Mon, Nov 10, 2003 at 09:53:22PM -0500, Stephen Gran wrote:
> > I am trying to write a regexp that lets me use grep (or really,
> > egrep) to read a standard conffile-style file.  This means that I
> > want to ignore any line that begins with a comment (for which I am
> > currently only allowing the use of #), any line that is just a
> > newline, and any line that is just whitespace (we don't need to
> > worry about the possibility of multiline strings in this case).  I
> > can come up with egrep -v '^#|^$' to ignore comments and _only_
> > newlines, but I would also like to ignore unseen whitespace (like
> > \s*) - [:space:] just doesn't seem to be working for me.  Can
> > somebody whack me with a cluebat?
> 
> The "[:space:]" needs to occur within a character class, which
> effectively requires the use of double square brackets.  Try:
> 
> 	egrep -v '^[[:space:]]*(#|$)'

Ah that explains my problem.  Thank you very much.  Just to mke sure I
am parsing your solution correctly, I read this as: if the line begins
with 0 or more spaces, followed by either # or newline, then ignore it -
yes?  That looks like exactly what I want.

-- 
 --------------------------------------------------------------------------
|  Stephen Gran                  | There is no substitute for good         |
|  steve@lobefin.net             | manners, except, perhaps, fast          |
|  http://www.lobefin.net/~steve | reflexes.                               |
 --------------------------------------------------------------------------

Attachment: pgpeNvhidF2OV.pgp
Description: PGP signature