Remove Duplicate Lines from a File - perl


/ Published in: Perl
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $file = '/path/to/file.txt';
  7. my %seen = ();
  8. {
  9. local @ARGV = ($file);
  10. local $^I = '.bac';
  11. while(<>){
  12. $seen{$_}++;
  13. next if $seen{$_} > 1;
  14. }
  15. }
  16. print "finished processing file.";

URL: http://www.daniweb.com/code/snippet631.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.