in reply to Removing Duplicate Lines from a File

This should only print each line in my_file.txt once:

perl -ne 'print unless $n{$_}++' my_file.txt

_______________
D a m n D i r t y A p e
Home Node | Email

Replies are listed 'Best First'.
Re: Re: Removing Duplicate Lines from a File
by johnirl (Monk) on Jul 17, 2002 at 15:35 UTC
    But how do I embed that into a perl program?
      If you run DamnDirtyApe's excellent one-liner through Deparse:
      perl -MO=Deparse -ne 'print unless $n{$_}++' my_file.txt
      you will see how:
      LINE: while (defined($_ = <ARGV>)) { print $_ unless $n{$_}++; }
      You can remove the LINE: label and you should add use strict.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
      my %uniq; $uniq{$_}++ while <DATA>; print for keys %uniq; __DATA__ B1 name;B1 Bmk;B1 host;B1 arch;B1 mem;B1 dvr;B1 arw; SomeName;Blondie;server15;unix;1;1;32 SomeName;Blondie;server15;unix;2;2;43 SomeName;Blondie;server15;unix;3;3;54 SomeName;Blondie;server15;unix;4;4;65: B1 name;B1 Bmk;B1 host;B1 arch;B1 mem;B1 dvr;B1 arw; SomeName;Blondie;server12;unix;1;5;76 SomeName;Blondie;server12;unix;2;6;87 SomeName;Blondie;server12;unix;3;7;89 SomeName;Blondie;server12;unix;4;8;09;

      HTH

      _________
      broquaint