bash shell – Tip of the Week: Those pesky comments!

Have you grown tired of going through lines and lines of comments in a configuration file, when all you want to see is what parameters are actually set?

Are you tired of using ‘grep -v‘ to eliminate the lines you don’t want to see?

Well, this handy little alias I’ve called nocomm in your .bash_profile can help.

Somewhere in your home bash profile ~/.bash_profile, create an inbuilt function and then alias it, like this:
.
.
.
grepvalues()
{
       grep -v ^# $1 | grep -v ^$
}

alias nocomm=grepvalues

… the alias becomes active at the next login (or immediately, if you source the file like this ‘. ~/.bash_profile‘)

The alias works by not showing any line beginning with a comment, nor any blank lines, like this:

[root@asus ~]# nocomm /etc/sysconfig/nfs

RQUOTAD=”/usr/sbin/rpc.rquotad”
RQUOTAD_PORT=10005
LOCKD_TCPPORT=30001
LOCKD_UDPPORT=30001
MOUNTD_PORT=10004
STATD_PORT=10002
STATD_OUTGOING_PORT=10003

Advertisements

About Michael Abboud

Linux / Unix Technical Specialist
This entry was posted in Linux / Unix Tips and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s