[Novalug] .bashrc favorite shortcuts
dc.loco at gmail.com
dc.loco at gmail.com
Fri Nov 7 17:57:14 EST 2008
On Nov 7, 2008 3:36pm, Greg <greg at lightdrizzle.net> wrote:
> I wrote:
> > Not being a regex wizard, it took me a while to construct this first
> > one but I use it all the time. It's probably my favorite, although no
> > doubt, someone else will have already invented something better. ;-)
> >
> > # Strips lines beginning w/ "#" and also removes blank lines
> > #
> > alias decomment='egrep -v "^[[:space:]]*(#.*)?$" '
>
> Not that it's better but this works as well:
>
> egrep -v '(^#|^$|^ .*#)'
I'm thinking that doesn't do what I'm looking for: I don't want to
eliminate all lines with comments. I want to eliminate lines that are
either entirely whitespace or entirely comments or entirely a combination
of the two. For example:
Source (assume a few spaces and tabs on the empty-looking line between
</Directory> and <Location>):
-----------------------------------------------------------------------------
| # Bla-bla-bla
| <Directory /yada>
| Set something # Something should be set here
| # Here's some more junk
| </Directory>
|
| <Location ...>
| Unset something # Temporarily unset this
| </Location>
-----------------------------------------------------------------------------
Using decomment gives me:
-----------------------------------------------------------------------------
| <Directory /yada>
| Set something # Something should be set here
| </Directory>
| <Location ...>
| Unset something # Temporarily unset this
| </Location>
-----------------------------------------------------------------------------
It's great with configuration files that have miles and miles of embedded
documentation and commented out defaults. I only see the lines that
actually *DO* something. Yours looks like it won't catch the line that has
nothing but tabs and spaces, but would eliminate the Set and Unset lines
above because they have comments at the end. Then again, I might be missing
something regex-ish. Wouldn't be the first time. ;-)
I keep thinking of generalizing it a bit more to cope with ";" or "//" or
whatever the user specifies as a comment initiator. But since 99% of what I
end up using it for uses "#" I've never gotten around to scratching that
itch.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://calypso.tux.org/pipermail/novalug/attachments/20081107/27fdc5c5/attachment.html
More information about the Novalug
mailing list