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

Who is Participating?
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.
Just do

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

Open in new window

beer9Author Commented:
Thank you :-)
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.