LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cleaner, Neater Configuration files (https://www.linuxquestions.org/questions/linux-general-1/cleaner-neater-configuration-files-881531/)

ramlubhai 05-18-2011 11:16 PM

Cleaner, Neater Configuration files
 
Not exactly new to Linux but - over the years I have been appalled to find hundreds of configuration files for every known program/service in Linux with millions of lines of useless comments that you have to endlessly scroll up-and-down in a text-editor to find anything of value and then make sense of what you need to configure/change, etc.

Is there an automated way to clean up any given configuration file and get rid of the "filler" stuff ??

Seems like a shell script should be able to accomplish the task by getting rid of all lines that start with # ..

Thanks.

Telengard 05-19-2011 12:13 AM

Quote:

Originally Posted by ramlubhai (Post 4360555)
Seems like a shell script should be able to accomplish the task by getting rid of all lines that start with # ..

grep -v '^#' dirty > clean

catkin 05-19-2011 12:19 AM

And empty lines:
Code:

grep -v "^#" < config.verbose | grep -v "^$" > config.terse

theNbomr 05-19-2011 12:21 AM

Is this a troll?... because I'm tempted to bite.
You must be a pretty smart person to think that the comments someone took the time to write are merely obfuscating the information. I've always viewed the ability to heavily comment configuration files as beyond good, but crucial. Do you save wasted disk space by deleting the man pages, too?
Looks like I have bitten...
--- rod.

salasi 05-19-2011 02:16 AM

Quote:

Originally Posted by catkin (Post 4360578)
And empty lines:
Code:

grep -v "^#" < config.verbose | grep -v "^$" > config.terse

Hmmm, a better idea might be to pipe the output to 'less' rather than create a new file (although that doesn't seem to be what the OP was asking for). That way you have a transient version that gives a quick summary.

OTOH, I've just tried it on an arbitrary but unfamiliar conf file, and it renders the file virtually unreadable (incomprehensible). Virtually unreadable, though compact, so scrolling is quicker, although, arguably, I might like it better on a conf file that I knew well. Maybe. You pays your money and you takes your choice, I suppose.

16pide 05-19-2011 02:47 AM

your solution is here: http://www.debian-administration.org...guration_files
Actually what i love is how they hide comments in vim without actually removing them. So you get the best of both worlds:
compact view that lets you view only the active lines, but at any time you can get any comment back. And if you save the document, the comments are untouched.

I just tried this in gvim which adds mouse support to vim, vim itself extending vi.

catkin 05-19-2011 03:26 AM

Quote:

Originally Posted by theNbomr (Post 4360582)
You must be a pretty smart person to think that the comments someone took the time to write are merely obfuscating the information. I've always viewed the ability to heavily comment configuration files as beyond good, but crucial.

For me they are crucial when the configuration is unfamiliar but do prevent "seeing the wood for the trees" when it's familiar. I always keep the original (typically renamed with a .org suffix) and, for heavily commented files, strip the comments. A benefit of this scheme is that searching for *.org files (and directories in the case of directories in which every file is used to configure) identifies all the configurations which have been customised since installation.

catkin 05-19-2011 03:27 AM

Thanks for the link 16pide :) Vim's hiding feature is new to me.

onebuck 05-19-2011 07:32 AM

Hi,

With today's hdd density I cannot see the reasoning behind removal of text comments within configure files.
Even before the higher disk density I would not remove comment text from configure files. Too many, plus there is no way that you could remember the conditions for all files. I have files that were written years ago and thankfully comments were there to refresh my memories.

You really should go through the vi tutorial.

So I guess the OP caught another one! :)

onebuck 05-19-2011 07:33 AM

@OP Welcome to LQ!

MTK358 05-19-2011 08:50 AM

Quote:

Originally Posted by onebuck (Post 4360811)
With today's hdd density I cannot see the reasoning behind removal of text comments within configure files.
Even before the higher disk density I would not remove comment text from configure files.

The reason the OP wanted to remove comments is not because of HDD space, but because they're hard to scroll through in an editor.

trey85stang 05-19-2011 09:02 AM

this should be a good note to the software devs, most people dont like commented config files... if we want the commenst we will type man someapp.conf

TobiSGD 05-19-2011 09:08 AM

I personally am a great fan of commented config-files. Since it is so easy to strip out the comments, or fold them in vim, I see no reason to get rid of the comments in standard configuration files.

catkin 05-19-2011 09:14 AM

It is nice to strip the comments and blank lines when posting on LQ ... ?

TobiSGD 05-19-2011 09:21 AM

Quote:

Originally Posted by catkin (Post 4360901)
It is nice to strip the comments and blank lines when posting on LQ ... ?

I agree with that, makes it easier to read them.


All times are GMT -5. The time now is 07:30 AM.