User Tools

Site Tools


computing:linux:strip_comments

Strip Comments

With ''grep''

grep -v '^$\|^\s*\#' <filemane>

Small Utility

FIXME

Create this tiny utility to view configuration files at their smallest and most readable form.

Many support organizations insist you strip comments from config files to make them more readable.

Create, install and make the utility executable (cut and paste the following at the command line as root):

cat << EOF >> /usr/local/bin/nocom
#!/bin/sh
# 'nocom' is a small tool to strip comments when viewing commented configuration files
# It's not perfect and may not work for you.  Note that it strips the initial "#!/bin/sh" too.
#
echo ""
cat \$1 | sed -e '/^\s*;/d' | sed -e '/^\s*\$/d' | sed -e '/^[[:blank:]]*#/d; s/[[:blank:]][[:blank:]]*#.*//'
EOF

chmod +x  /usr/local/bin/nocom

Then use the new utility like this:

nocom /path/to/config/file
computing/linux/strip_comments.txt · Last modified: 2015/10/19 10:00 by gcooper