Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:-

culturaurbanashop.com,remaxcorn.info,enjoygoing.com,full-kit-wankers.co.uk,paracaballo.com,radiopozarica.com,sprinklermaps.com,unlock-any-phone.com,voipbillingplus.com,yedincicadde.net,klasseaparte.com,allfortheweb.com,indulgesolutions.com,fastextcafe.info,titi.sickworldhosting.com,kebeico.com,facemowi.it,mellat.info,sal-gov.info,hindustan4848.com,nawaopls.co.za,familie-ries.de
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Try:

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

 
discard

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.