Remove comment from files
posted by pennegaonMonday February 21st, 2011, 32312 total view
Sooner or later it happens to everyone having to edit a config file.
Usually the operation is simple, just open a text editor (nano, vi, emax, kate, gedit, etc.) and modify the lines of our interest.
The thing starts to get complicated when the configuration files are very rich in comments that make reading difficult.
How to proceed?
We can remove all lines that contain comments, leaving only the configuration directives.
Before you remove the comments it is good to make a copy of the original file (they can always come back to help):
cp file_di_conf.conf file_di_conf.conf.ori
Now through grep you can proceed to delete comments:
cat file_di_conf.conf.ori | grep -v -E '(^#|^$)' > file_di_conf.conf
Now the configuration file will be without comment.
NB:For comments means the line starting with #.
Tanks to xnamix