Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I was wondering what command should I use to find duplicate names in a file. This is a descent sized file and I need to make sure that there are no duplicate names throughout the whole file. Thanks again for any help. Here is was I have so far and Im going to try using the sort command.
You can use the sort command with -u option to get unique records from a file.
Say you have a file called "list" with the following contents:
You can see bob is in there twice. If you run "sort -u list" it will show only:
You could redirect that into a new file move it over the original.
Of course if you don't have the entire line the same on every occurrence the sort -u won't exclude it. So if your list had:
Both lines would be output because the second field is different.
Well the file contains only names but and I just want to make sure there are no duplicates. I dont think the sort command would work because the duplicates would still be there it just wouldnt show them. I want to see if there is any so I can later delete the duplicates.
A better question is can the /etc/passwd file actually contain duplicate login names? I don't think it can, unless added manually, duplicate uid/gid sure, but I don't think the useradd/adduser command will let you dup the name.