pavan.gup has asked for the wisdom of the Perl Monks concerning the following question:
I have a configuration file in the following format:
DEVICE=eth0 ONBOOT=yes BOOTPROTO=static TYPE=Ethernet IPADDR=10.9.0.200 NETMASK=255.255.0.0 GATEWAY=10.9.1.254
Some of the parameters above need to update. E.g. IPADDR needs to be updated to say 1.2.3.4. I have written a function that reads the entire file:
sub read_file { local $/ = undef; open FILE, $_[0] or die "Couldn't open file: $!"; $_[1] = <FILE>; close FILE; }
I call it read_file("config.txt", $file_content); Now $file_content has the entire file in form of string. I don't have option to install packages so need to use standard Perl. Can anyone please help in coming up with perl syntax that would update the config file parameters in the string. I can then write the string back to the file.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Update config file parameters
by Athanasius (Archbishop) on Jan 05, 2016 at 13:17 UTC | |
Re: Update config file parameters
by hdb (Monsignor) on Jan 05, 2016 at 14:46 UTC | |
by GotToBTru (Prior) on Jan 05, 2016 at 14:58 UTC | |
Re: Update config file parameters
by u65 (Chaplain) on Jan 05, 2016 at 11:59 UTC | |
Re: Update config file parameters
by Anonymous Monk on Jan 05, 2016 at 13:53 UTC | |
Re: Update config file parameters
by 7stud (Deacon) on Jan 07, 2016 at 05:59 UTC | |
by afoken (Chancellor) on Jan 07, 2016 at 21:38 UTC | |
Re: Update config file parameters
by dbuckhal (Chaplain) on Jan 06, 2016 at 22:37 UTC | |
by afoken (Chancellor) on Jan 07, 2016 at 21:12 UTC | |
by dbuckhal (Chaplain) on Jan 08, 2016 at 05:09 UTC | |
by afoken (Chancellor) on Jan 08, 2016 at 20:14 UTC | |
by dbuckhal (Chaplain) on Jan 09, 2016 at 00:15 UTC |