Not really. It just seemed like a logic entry point to start with. And yes, If I don't find the given entry in the file I the script will then append to the bottom or by some marker within the file.
#!/usr/bin/perl ###################################################################### ##################################################################### #################################################################### ################################################################### # Set Variable file modification #**************************************************************** $datefile = `date '+%m%d%y'`; # Copy current /etc/hosts file to the work directory (/etc/work/hostsf +ile) #************************************************************* # Search and file section for hosts file entry #Main Program format STDOUT = @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +> "********************************************************************* +" @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "*******************************************************************" @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "****************************************************************" @||||||||||||||||||||||||||||||||||||||| "ETC Hosts File Inplace Edit Program" @||||||||||||||||||||||||||||||||||||||||||||||||||||| "Inplace Edit (Work Directory: /etc/work/hostfiles)" @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "****************************************************************" @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "*******************************************************************" @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +>> "********************************************************************* +*" . write; ########################### Main Program Section ##################### +### print "\n"; print "This program is will copy the current etc/hosts file to the \n" +; print "working directory (/etc/work/hostfile) to perform the \"Inplace +\,\" \n"; print "edit of the new or modified directories. \n"; print "\n"; print "Should I continue with the process, or exit for another time? ( +Yes|No): "; $choice1 = <STDIN>; chomp($choice1); while ($choice1 =~ m/No|NO|no|N|n/) { print "Now exiting the program. \n"; print "Please wait . . . .\n"; `sleep 5`; exit; } print "Please enter the following the following information . . .\n"; print "New System IP Address (Example - 10.12.13.14): "; $NewIP = <STDIN>; chomp($NewIP); print "Absolute name of system or device (Example - neptune.itdo.pri): + "; $NewLgName = <STDIN>; chomp($NewLgName); print "Short name of system or device (Example - neptune): "; $NewStName = <STDIN>; chomp($NewStName); ######################## Array ####################################### +## @input = ($NewIP, $NewLgName, $NewStName); ######################## Sub Routine Call Section #################### +### &copyFile; &editPlace(*input); ########################### Sub Routine Section ###################### +### sub copyFile { `cp /etc/hosts /etc/work/hostfiles/hosts`; $TargetDir = "/etc/work/hostfiles"; $TargetFile = "/etc/work/hostfiles/hosts"; `cp $TargetFile /etc/work/hosts.workcopy`; `chmod 777 /etc/work/hosts.workcopy`; `mv $TargetFile $TargetFile.orig.$datefile`; } sub editPlace { #$datefile = `date '+%m%d%y'`; local(*thisIP) = @_; $WorkCopy = "/etc/work/hosts.workcopy"; open(HOSTS, $WorkCopy) || die "Can't open hosts.workcopy $!\n" +; LINE: while(<HOSTS>) { next LINE if /^#/; next LINE if ! /$thisIP[0]/; ($IP, $longhostname, $shorthostname, $devicealias)=split(" +"); print "$IP\t $longhostname\n"; } close(HOSTS); } It's not done, but you can see the idea arising.

In reply to Re^2: Any Simple Examples of File::Tasks::Edit by Preston@Large
in thread Any Simple Examples of File::Tasks::Edit by Preston@Large

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.