My /etc/passwd
has a list of users in a format that looks like this:
username:password:uid:gid:firstname.lastname, somenumber:/...
Goal : I want to see only the first names and than sort them having the most common name appear first, 2nd most common appear 2nd etc....
I saw some solutions as to how to do the 2nd part, although they are relevant to working with a text file and not to reading from a map.
In regards to the first part, I really don't know how to approach this. I know that there are some solutions but don't really know how to do them.
uniq
without-i
, since there should be difference between X and x in name, we only need --ignore-case option for sort as you've used. In addition, using the sed command you've added in your answer, seems irrelevant, if there is any reason, please explain. – Aug 09 '16 at 08:07-i
:John.Doe
should be the same asjohn.doe
. Re:sed
: from the OP: I want to see only the first names. – Satō Katsura Aug 09 '16 at 08:13sed '/\n/{P;d};s/:/\n/4;s/\./\n/;D'
orsed 's/[^.]*:\(\w\+\).*/\1/'
– Costas Aug 09 '16 at 08:23sed
>> the time gained by not usingcut
. BTW, your second recipe assumes GNUsed
(\w
). – Satō Katsura Aug 09 '16 at 08:31sed 's/[^.]*://;s/\..*//'
. But my 1st example a little bit quicker. AND if you don't like\w
you free to use[:alnum:]
– Costas Aug 09 '16 at 08:38sed 's/[^.]*://;s/\..*//'
misses any names without dot. The point of usingcut
is precisely to avoid going into this kind of details, you know. – Satō Katsura Aug 09 '16 at 08:44s/\([^:]*:\)\{4\}//;s/[:.].*//
In any way if you involve sed you can easily avoid cut – Costas Aug 09 '16 at 09:46sed
andcut
part) – asaf92 Aug 09 '16 at 13:29ypcat passwd
to read it. – asaf92 Aug 09 '16 at 13:31cut
extracts the 5th field,sed
kills the.lastname, somenumber
part out of it. You can, of course, do it like this:ypcat passwd | cut -d: -f5 | ...
. – Satō Katsura Aug 09 '16 at 13:48