Use a perl script to parse a file then update /etc/hosts
Im working on one last perl script to update my /etc/hosts file, but am stuck and wondered if someone can help please?

I have a text file with an IP in it, and need to have my perl script read this, which iv done, but now im stuck on updating the /etc/hosts file.

here is my script so far:

    #!/usr/bin/perl
    
    use strict;
    my $ip_to_update;
    
    $ip_to_update = `cat /web_root/ip_update/ip_update.txt | awk {'print \$5'}` ;
    
    print "ip = $ip_to_update";

I then need to find an entry in /etc/hosts like 

remote.host.tld 192.168.0.20

so i know i need to parse it for remote.host.tld and then replace the second bit, but because the ip wont be the same i cant just do a straight replace.

Can anyone help with the last bit please as im stuck :(

Thankyou!
Use a perl script to parse a file then update /etc/hosts
===

Im working on one last perl script to update my /etc/hosts file, but am stuck and wondered if someone can help please?

I have a text file with an IP in it, and need to have my perl script read this, which iv done, but now im stuck on updating the /etc/hosts file.

here is my script so far:

    #!/usr/bin/perl
    
    use strict;
    my $ip_to_update;
    
    $ip_to_update = `cat /web_root/ip_update/ip_update.txt | awk {'print \$5'}` ;
    
    print "ip = $ip_to_update";

I then need to find an entry in /etc/hosts like 

remote.host.tld 192.168.0.20

so i know i need to parse it for remote.host.tld and then replace the second bit, but because the ip wont be the same i cant just do a straight replace.

Can anyone help with the last bit please as im stuck :(

Thankyou!