[juneau-lug] Annoying comments

  • From: "James Zuelow" <James_Zuelow@xxxxxxxxxxxxxxx>
  • To: "Juneau Linux Users Group" <juneau-lug@xxxxxxxxxxxxx>
  • Date: Tue, 21 Mar 2006 18:59:24 -0900

In the past few days I've been dealing with a lot of default installed config 
files for daemons like Samba and Squid.  The developers of these packages are 
very good at documenting their config files with lines and lines of comments 
explaining every option I might need to use, as well as explaining the many 
options I don't need.
So when I want to make a change, I have to search for the value I want to 
change and end up hitting all of the times it is referenced in the comments 
before it is actually set.  Not to mention the effects of some management tools 
like YaST, which likes to leave the original comment in place and then put it's 
own entries at the end.

So I put this together to kill the commented out lines, leaving me with just 
the values I need.  Takes a default XF86Config file from 14k to 2k, which I 
find easier to work with.  Long commented configs (like Squid) can have huge 
numbers of blank lines left over after killing the comments, so I kill those 
too.

You can pass a filename to the script, and if you don't it will prompt you for 
one.  There's no sanity checks on what you enter, so be careful.  It won't 
delete or move the original config, you have to do that yourself.

Also note that some config files actually parse lines that begin with a hash.  
I ran across one like that in the past few days, but now I can't remember for 
the life of me what it was.  (All I can remember is that the actual comments 
all had double-hashes, and there was a comment telling you not to delete the 
single hashes.)  I'll probably remember what it was next week sometime.

Anyway,

James

---------------------------------------------------------------------------

#!/bin/bash
############################################################################
# cleanfile.sh
# James Zuelow // Juneau Linux Users Group
# 21 March 2006
############################################################################
echo -e "\nCaution! Do not use cleaned config files which expect lines to"
echo -e "begin with hash characters (#) or need blank lines!\n"
if [ -z $1 ]; then
        echo -n "Which file to clean comments and whitespace? (enter quits):"
        read conffile
        if [ -z ${conffile} ]; then exit; fi
else
        conffile=$1
fi
sed -n '/^#.*/!p' ${conffile} | sed -n '/^$/!p' > ${conffile}_clean
echo "${conffile} cleaned and saved as ${conffile}_clean"
exit

------------------------------------
The Juneau Linux Users Group -- http://www.juneau-lug.org
This is the Juneau-LUG mailing list.
To unsubscribe, send an e-mail to juneau-lug-request@xxxxxxxxxxxxx with the 
word unsubscribe in the subject header.

Other related posts:

  • » [juneau-lug] Annoying comments