Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a comma-separated list of domain-names in a file; unfortunately there are duplicate entries for some domain-names.

Is there a way to find and remove the duplicate entries from the file?

The sample output is as below:-

share|improve this question
up vote 3 down vote accepted


tr ',' '\n' < infile | sort -u | paste -sd, -
share|improve this answer

If you mean that duplicates should be removed from coma separated lists of words (where words are sequences of non-blanks), then maybe something like:

$ echo 2,1,1,2,c,1 a,a,a,b,c | perl -M'List::MoreUtils uniq' -lpe '
    s/[\S,]+,[\S,]+/join ",", uniq(split",",$&)/ge'
2,1,c a,b,c
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.