How do I edit files with Perl 
Author Message
 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.


Sat, 04 Mar 1995 19:40:46 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. edit a file without /tmp file

2. Editing files on PC(Compatilbes) using PERL

3. Question - using perl to edit text files

4. Editing PDF files with perl

5. getting perl to edit a file

6. perl edit in place file globbing problem on windows

7. editing pdf files via perl

8. Question on Perl Faq 9 - Editing .htaccess files

9. Q: about Perl and editing .wav files.

10. Inplace file editing within a perl program

11. in line editing of a file using perl

12. How do I Use Perl to edit part of a file but not overwrite it all

 

 
Powered by phpBB® Forum Software