Monday, October 3, 2011

Removing comments from configuration files with sed

Using the below one liner I do what the $subject of the post says:

 sed -e '/^;/d' -e '/^$/d' /etc/php.ini > /tmp/php.ini-stripped

-e '/^;/d'     -- deletes the lines starting with ; and this can be changed to # of course;
-e '/^$/d' /  -- deletes the white lines resulted after the above command;

2 comments:

  1. # perl -lane 'print if !/^;/&!/#.*/&!/^$/' /etc/fstab

    for any of them (; # white lines)

    ReplyDelete
  2. Also doable with egrep -v '#|;|^$' /etc/apache2/apache2.conf

    ReplyDelete