LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices

Reply
 
Search this Thread
Old 03-23-2009, 02:33 AM   #1
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Rep: Reputation: 15
Get duplicated names listed in /etc/passwd including the line number...


I've been at this all day today and for some odd reason I can't get what I am doing wrong. What I am trying to do is run a command that will list only the duplicated names and show what line that duplicated name is on. Say for instance I run a particular command and it outputs this:

111 Timonthy Johnson
465 Tomonthy Johnson

and so forth.

So basically I'm trying to get a list of duplicated names that are indentical, but also get the line number of where it is in the list. I hope that makes sense? Here is what I have so far as a command:

Code:
cut -f5 -d: /etc/passwd | uniq -D |
Any suggestions? Like I said, I've been wracking my brain around this and haven't been able to find the solution. I'm not sure if I'm not looking in the right place or what.

I know that uniq -D part of the command lists only and all duplicated lines, which is what I want. But the part that I'm stumped on is getting what line it is on. Gosh, I hope I'm making sense of what I'm trying to do. lol
 
Old 03-23-2009, 03:39 AM   #2
trist007
Member
 
Registered: May 2008
Distribution: Slackware
Posts: 972

Rep: Reputation: 56
Try this:

cat /etc/passwd | cut -d " " -f2 | uniq -d

dunno, not sure if you can pipe uniq -d
 
Old 03-23-2009, 04:16 AM   #3
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
It didn't work, it gave an output of a blank file. Anyone else willing to give this a shot?
 
Old 03-23-2009, 07:51 AM   #4
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 85
You could try this:

Code:
for line in $(cut -f5 -d: /etc/passwd | grep -v "^$" \
| sort | uniq -d);\
do grep -n $line /etc/passwd; done
I found I needed the first grep statement to remove multiple blank lines, and then to sort the output (as uniq works on successive identical lines), then feed each line back into grep to get the line numbers it occurs on.

Not perfect, but should do the job.

Last edited by Robhogg; 03-23-2009 at 07:56 AM. Reason: Readability
 
Old 03-23-2009, 10:05 AM   #5
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
I was hoping to keep it a command, and not a script type deal. I am not trying to be a butt about it. lol I also want to keep the anything after the first pipe can be altered as to what I have, but everything before the first pipe I would like to stay the same.

cut -f5 -d: /etc/passwd |

Keep what is in red, but was hoping there was something we could add at the end of command to get the result I was hoping to get. I hope that makes sense? Hope I'm not being a pain.
 
Old 03-23-2009, 10:37 AM   #6
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 85
Quote:
Originally Posted by shorte85 View Post
I was hoping to keep it a command, and not a script type deal...
I tried to find a way to do it like that, but eventually gave up. If there is a way, it will take someone who is more expert than me to work it out.

Rob

Last edited by Robhogg; 03-23-2009 at 10:38 AM. Reason: Compliance with English 4.1
 
Old 03-23-2009, 10:52 AM   #7
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
Alright, thanks for trying. I appreciate it, and that goes for trist007 as well. Maybe someone else has a solution to my problem, ha!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash : read every line from text file starting at given line number quadmore Programming 4 02-20-2009 12:29 PM
!? element names beginning with number break javascript??? UMG:Chicken_Sop Programming 1 01-27-2008 11:12 PM
Where can I find black listed DNS names (not spam) OlRoy Linux - Security 11 12-26-2007 07:43 AM
Including Keystrokes on the Command Line hroit Linux - General 6 12-24-2007 04:22 PM
Istalling rpm INCLUDING dependencies via command line? rgerhards Linux - Software 1 10-08-2003 03:35 AM


All times are GMT -5. The time now is 02:23 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration