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 | 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 |
Try this:
cat /etc/passwd | cut -d " " -f2 | uniq -d dunno, not sure if you can pipe uniq -d |
It didn't work, it gave an output of a blank file. Anyone else willing to give this a shot?
|
You could try this:
Code:
for line in $(cut -f5 -d: /etc/passwd | grep -v "^$" \ Not perfect, but should do the job. |
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. |
Quote:
Rob |
Alright, thanks for trying. :) I appreciate it, and that goes for trist007 as well. :) Maybe someone else has a solution to my problem, ha!
|
All times are GMT -5. The time now is 02:04 PM. |