URL: http://answers.google.com/answers/threadview?id=25196
Sometimes I get a big list of things, and some of the things occur multiple times in the same list. To make the list easier to read, I want to delete the duplicate lines.
A good example is a list of files that have errors (maybe excerpted from an application sever's log files). In that case you have a newline-delimited list of file paths, and depending upon the situation, the same file path might be listed 4 or 5 times or more. Often, it is useful to have a list of just the files that are faulty, which can be produced by deleting all the duplicate lines. This script is for filtering just those kinds of list files.
Of course, for Emacs users there is a much easier way to remove duplicate lines:, if you have uniq installed on your system.
M-x sort-lines RET C-x h M-x shell-command-on-region RET uniq RET
Comments
Subscribe to comments
You need to login to post a comment.

Hi, My input file is like this
Hai How are you Hai How are you Hai How are you Hi Hai How are you Hi
But i got the output like this after running the above script what might be the problem
Hai How are you Hi Hi
it should have removed the last string 'Hi' too but why it is not removing.
Any help would greatly appreciated.
@karthiksomu, as written the script considered trailing whitespace to be significant. So "Hi " is not the same as "Hi"
I'm not sure that was the problem in your case. But I've fixed the script so that it now ignores trailing whitespace, so try it again and see if that solves your problem?
Another (better) option would be to use
sortanduniqto do this job:@karthiksomu, as written the script considered trailing whitespace to be significant. So "Hi " is not the same as "Hi"
I'm not sure that was the problem in your case. But I've fixed the script so that it now ignores trailing whitespace, so try it again and see if that solves your problem?
Another (better) option would be to use
sortanduniqto do this job:Ack! Double posted! How embarrassing. Now I can never use the internet again due to shame :(
Nice and easy piece of code, thank you. It saves my time.
Nice and easy piece of code, thank you. It saves my time.