Latest Lists

How do you find the duplicates in a string array in unix?

I don't want to delete the duplicates I want a list of duplicates in the array the (array is a string)

Public Comments

  1. This would be a lot easier to do with hashes in Perl, but whatever. Basically l know how to do this if you're allowed to create files in the script. Output the elements of the array and redirect to a file. Replace the spaces (separating the elements) with new lines. Then sort the file, which will make all the lines in order. Then use the command uniq -d on the file to remove everything that isn't a duplicate. Now just output the contents of the file, and that's it.
Powered by Yahoo! Answers