hi!
I want to comment and uncomment 2 lines in my config files that goes like:
CONTACT_LIST="abc@xyz.com;"
#CONTACT_LIST="def@xyz.com;"
I want to sawp the commnets in above lines and desired output should be:
#CONTACT_LIST="abc@xyz.com;"
CONTACT_LIST="def@xyz.com;"
Please suggest.
A more general solution...save as switch_comments.pl and call switch_comments file.cfg CONTACT_LIST
#!/usr/bin/perl
use strict;
use warnings;
open (my $config, '<', "$ARGV[0]);
open (my $temp , ">", "$ARGV[0].tmp");
while (<$config>){
$_=$1 if /^\s*#($ARGV[1].+$)/;
$_ = "#$_" if /^$ARGV[1]/;
print $temp $_;
}
close $temp;
close $config;
rename("$ARGV[0].tmp", $ARGV[0]);