How to fetch username from /etc/passwd using perl?

Hello, I am trying to below one liner to fetch the login name from the /etc/passwd file, though I want to get the username in the array instead of scalar. Could someone suggest me other options? Thanks!
perl -nle '($user) = split (/:/); print $user' /etc/passwd

Open in new window

beer9Asked:
Who is Participating?
 
robthewolfCommented:
split gives you an array.
so you need to figure out which number element of the array the data you and is and print that by writing
print $user[x]
where x is the 0 indexed position in the array that you want.
0
 
TintinCommented:
Just do


perl -F: -lane 'print $F[0]' /etc/passwd

Open in new window

0
 
beer9Author Commented:
Thank you :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.