Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How to write a new line in a while loop?

by gsiems (Chaplain)
on Oct 06, 2009 at 22:16 UTC ( #799603=note: print w/ replies, xml ) Need Help??


in reply to How to write a new line in a while loop?

If I understand you correctly, you are wanting to do the equivalent of:

grep -v IPADDR "$dir/$sys/$ifdir/$if0" > "$dir/$sys/$ifdir/${if0}.new" echo "IPADDR=1.1.1.1" >> "$dir/$sys/$ifdir/${if0}.new"

at the command line. If this is the case, do you really need perl for this or is this part of a larger script/problem?

--gsiems

Update: Looking closer, I see that I missed the BOOTPROTO line. Is this closer to what you are looking for (not tested):

print "Please enter the ip address for this machine. This will be eth +0:\n"; my $ip = <>; chomp $ip; my $if0 = "ifcfg-eth0"; my $if1 = "ifcfg-eth1"; my $ifdir = 'network-scripts'; my $ifsub1 = "IPADDR="; my $ifsub2 = "BOOTPROTO="; my $ifsub3 = "none"; my $IP; my $NEW; open ($IP, "<", "$dir/$sys/$ifdir/$if0"); open ($NEW, ">", "$dir/$sys/$ifdir/$if0.new"); my @ary = ( grep { $_ !~ m/IPADDR/ } (<$IP>)); s/($ifsub2).+$/$1$ifsub3/ for @ary; print $NEW @ary; print $NEW "IPADDR=$ip\n"; close $IP; close $NEW;


Comment on Re: How to write a new line in a while loop?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://799603]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2015-08-01 00:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls