Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
QuickTip: Posting Config Files On The Forum
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
beowulf
Apprentice
Apprentice


Joined: 07 Apr 2003
Posts: 225

PostPosted: Tue Jun 03, 2003 6:30 am    Post subject: QuickTip: Posting Config Files On The Forum Reply with quote

QuickTip: Posting Config Files On The Forum...

I've noticed quite a lot of posts where a user posts their config file in it's entirety (sp?). Not only is there a lot of un-needed information there, it makes the post larger than it needs to be, thus increasing DB query time, page load time and bandwidth to serve a page.

When posting config files, there is usually a very large section that is commented... when posting your config files, save on the space used in the forum's DB and reader's scrolling.

To generate your config file, try this out:
Code:
grep -v "^#" [filename]

As an example, let's grep the make.conf file which is littered with comments.
Code:
 grep -v "^#" /etc/make.conf

As you can see, the output is far less than what it would be should you copy and paste the entire config file into your post.

You can do this with any commented file.. what about a file that uses semi-colons ";" as coments. here's how it looks:
Code:
 grep -v "^;" [filename]



As you can see, the amount of information you post is far less... how much less? here's an example... My /etc/make.conf file is 12291 bytes. My grep'd make.conf file is 597 bytes. That's a saving of 11 kilobytes! Now imagine 100 unique page views on that page. That's 1.11 Megabytes we've saved. Again, multiply that by say an average of 10 posts like this per week, we've saved 11 megabytes of bandwidth... Resource usage is saved like this as well (cpu cycles, disk usage, memory)... Although the example is extreme, every little bit helps in my opinion....

Just a quick tip that may help you help the server...

[edit: fixed a few grammatical/spelling errors /]
_________________
I have nothing witty to say here... ever :-(


Last edited by beowulf on Sat Jun 07, 2003 8:48 am; edited 1 time in total
Back to top
View user's profile Send private message
dberkholz
Developer
Developer


Joined: 18 Mar 2003
Posts: 1008
Location: Minneapolis, MN, USA

PostPosted: Tue Jun 03, 2003 3:55 pm    Post subject: Reply with quote

Great tip. Everyone ought to do this, and you've made it even clearer.
Back to top
View user's profile Send private message
duff
Guru
Guru


Joined: 19 Jun 2002
Posts: 466
Location: Clemson, SC

PostPosted: Tue Jun 03, 2003 5:14 pm    Post subject: Reply with quote

Just to take this a step further, after the grep you can pipe it into sed to remove any intial blank lines and reduce 2 or more consecutive blank lines into 1.

Code:
grep -v "^#" [filename] | sed '/./,/^$/!d'

Save your scroll wheel some work! :wink:
Back to top
View user's profile Send private message
water
Guru
Guru


Joined: 19 Jun 2002
Posts: 387
Location: Zierikzee, The Netherlands

PostPosted: Fri Jun 06, 2003 4:58 am    Post subject: Reply with quote

Nice :D

i was just thinking about a little script to cleanup config-files. This is some very usefull input. :D
_________________
Groeten uit Holland
Back to top
View user's profile Send private message
bsolar
Bodhisattva
Bodhisattva


Joined: 12 Jan 2003
Posts: 2764

PostPosted: Fri Jun 06, 2003 5:19 am    Post subject: Reply with quote

Thanks for trying to help the forums. :wink:

If I can add, another problem is that it's not possible to wrap a line without whitespaces. This causes sometimes very wide pages and the need of scrolling horizontally and it's very annoying.
_________________
I may not agree with what you say, but I'll defend to the death your right to say it.
Back to top
View user's profile Send private message
beowulf
Apprentice
Apprentice


Joined: 07 Apr 2003
Posts: 225

PostPosted: Fri Jun 06, 2003 5:37 am    Post subject: Reply with quote

Thanks for that sed line! i made it an easy to type script now... called confviewer hehe... It's not very flexible... but it saves me from typing all that stuff...
Code:

#!/bin/bash
if [ "$2" == '' ]
then
grep -v "^#" $1 | sed '/./,/^$/!d'
else
        grep -v "^$2" $1 | sed '/./,/^$/!d'
fi

Probably not the best, but it works...
Code:

$ confviewer ~/.wine/config ";"
$ confviewer /etc/make.conf

_________________
I have nothing witty to say here... ever :-(
Back to top
View user's profile Send private message
water
Guru
Guru


Joined: 19 Jun 2002
Posts: 387
Location: Zierikzee, The Netherlands

PostPosted: Fri Jun 06, 2003 6:01 am    Post subject: Reply with quote

I think it would be a good idea to save the original file.
_________________
Groeten uit Holland
Back to top
View user's profile Send private message
red_over_blue
Guru
Guru


Joined: 16 Dec 2002
Posts: 310

PostPosted: Fri Jun 06, 2003 6:23 am    Post subject: Reply with quote

grep and sed don't change the file. If you wanted to, you could do something like:

Code:

grep -v "^#" /etc/make.conf > /etc/make.conf.new


and then look at it, decide for sure you want it, and replace /etc/make.conf with /etc/make.conf.new
Back to top
View user's profile Send private message
water
Guru
Guru


Joined: 19 Jun 2002
Posts: 387
Location: Zierikzee, The Netherlands

PostPosted: Fri Jun 06, 2003 6:46 am    Post subject: Reply with quote

red_over_blue wrote:
grep and sed don't change the file. If you wanted to, you could do something like:

Code:

grep -v "^#" /etc/make.conf > /etc/make.conf.new


and then look at it, decide for sure you want it, and replace /etc/make.conf with /etc/make.conf.new
Uh, yepz :?

I was thinking about the idea to clean up the config-files on your own computer.
_________________
Groeten uit Holland
Back to top
View user's profile Send private message
duff
Guru
Guru


Joined: 19 Jun 2002
Posts: 466
Location: Clemson, SC

PostPosted: Fri Jun 06, 2003 12:23 pm    Post subject: Reply with quote

bsolar wrote:
If I can add, another problem is that it's not possible to wrap a line without whitespaces. This causes sometimes very wide pages and the need of scrolling horizontally and it's very annoying.


Code:
# <grep'n'sed> | fold -w 60 -s


That should take care of it...60's good line length for people with low resoultion, isn't it?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum