Remove comment from files

posted by onMonday February 21st, 2011, 30590 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

1 Replay for “Remove comment from files”

  1. ermanno says:

    Grazie, è quello che mi serviva.
    Buona giornata.
    ermanno

Leave a Reply

Your email address will not be published. Required fields are marked *