How do I edit files with Perl
I have a script which generates password file details and creates a home
directory for new user accounts.
I need to modify my script to ensure the contents of input data files will
be unique (in particular the logname) to the password file before altering
the password file.
I've written a noddy script to test my ideas.
What I've decided to do is grep the password file for lognames obtained from
the input files. If I come across any I save them to a list and print the
details in a file for later reference.
I then use a line adapted from the "Common Tasks with Perl" chapter to remove
the line in each file where the offending string occurs.
$SysFile = "/home/staff/csm/c_brown/Scripts/Perl_scripts/pass";
$Tmp = "/home/staff/csm/c_brown/Scripts/Perl_scripts/";
# This section finds the duplicates
open(Duplicates, ">>${Dups}");
print Duplicates $Date;
print STDOUT "Doing $new_data .... \n";
open(NewData, "+<${Tmp}${new_data}");
while(<NewData>) {
($Login) = split;
chop($crud = `grep $Login $SysFile`);
if ("$crud" ne "") {
print Duplicates $_;
}
}
close(NewData);
Quote:
}
# This section removes the offending lines
Quote:
}
My questions are:
1. Does anyone know of a neater way of achieving the same goal?
only work with the -pi.bak option? I don't really want the .bak files.
3. Why does the same line process the .bak files? Files test_data1.bak and
test_data2.bak are exactly the same as test_data1 and test_data2 respectively.