in reply to Remove Duplicates from one text file and print them in another text file.

Since your time frame is very very less, and presumably this isn't homework that has to be done in Perl, you might want to avoid reinventing the wheel (utilities available in any *nix system including Cygwin):

sort file.txt | uniq -d > duplicates.txt

Aaron B.
Available for small or large Perl jobs; see my home node.

  • Comment on Re: Remove Duplicates from one text file and print them in another text file.
  • Download Code

Replies are listed 'Best First'.
Re^2: Remove Duplicates from one text file and print them in another text file.
by bedohave9 (Acolyte) on Jun 05, 2012 at 17:07 UTC

    I am working on .NET 4.0 and Windows 7 is my OS. The code threw an error. Probably this is for Unix/Linux OS. Please correct me if I am wrong. Backslash found where operator expected at C:\Programs\CPGD\PerlScripts\remdup1.pl line 4, near "Users\" Backslash found where operator expected at C:\Programs\CPGD\PerlScripts\remdup1.pl line 4, near "spullabhotla\" Backslash found where operator expected at C:\Programs\CPGD\PerlScripts\remd up1.pl line 4, near "Desktop\" syntax error at C:\Programs\CPGD\PerlScripts\remd\remdup1.pl line 4, near "sort C :" Execution of C:\Perl64\Perl Programs\Learning\remdup1.pl aborted due to compilation errors.

      I am working on .NET 4.0 and Windows 7 is my OS. The code threw an error. Probably this is for Unix/Linux OS. Please correct me if I am wrong.

      Backslash found where operator expected at C:\Programs\CPGD\PerlScript +s\remdup1.pl line 4, near "Users\" Backslash found where operator exp +ected at C:\Programs\CPGD\PerlScripts\remdup1.pl line 4, near "spulla +bhotla\" Backslash found where operator expected at C:\Programs\CPGD\ +PerlScripts\remd up1.pl line 4, near "Desktop\" syntax error at C:\Pr +ograms\CPGD\PerlScripts\remd\remdup1.pl line 4, near "sort C :" Execu +tion of C:\Perl64\Perl Programs\Learning\remdup1.pl aborted due to co +mpilation errors.

      Yes, utilities like sort and uniq are available in Unix/Linux operating systems. On Windows, you can install a package called Cygwin, which will give you a Unix-like environment and command line, plus those common utilities.

      Aaron B.
      Available for small or large Perl jobs; see my home node.

        There is also GnuWin32, a set of GNU utilities compied as native Windows executables (no MinGW, no CygWin).

        (Update:) And of course, GNU Utilities for Win32, old but good, just extract the ZIP file somewhere, add the directory to $ENV{PATH}, and you are done. This is what I use on Windows.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)