Display shortest username and largest username on computer in Linux -


i'm trying configure script displays users on computer, groups belong to, , shortest/longest usernames.

i have first part set users , groups can't figure out shortest/longest username

question bit unclear-- scripting in language? bash?

if so, length of string variable $foo available ${#foo}. example longest user name do:

grep -eo '^([^:]+)' /etc/passwd |  while read name   echo ${#name} ${name} done | sort -n | tail -1 | awk '{print $2}' 

the grep command finds usernames in password file (all text beginning first colon).

the while loop outputs lengths of names along names themselves.

sort -n sorts output of while loop numerically.

tail -1 takes last line sorted output, biggest number.

awk '{print $2}' prints second column of output, name.

the shortest name same except using head -1 instead of tail -1.

keep in mind there tie. there lots , lots of other ways this, including using other scripting languages.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -