in reply to printing passwd file

If you want a one-liner:
perl -lne 'print ((split /:/)[0])' /etc/passwd

I noticed that you specified that the output should contain the user name as well as the name, but your code only displayed the user name. If you need both:

perl -lne 'print ((split /:/)[0] . " " . (split /:/)[4])' /etc/passwd

Replies are listed 'Best First'.
Re^2: printing passwd file
by ambrus (Abbot) on Mar 14, 2005 at 17:53 UTC

    You can also use this:

    perl -wlne 'print join " ", (split /:/)[0, 4]' /etc/passwd
      And arbitrarily playing golf:
      perl -lne 'print "@{[(split /:/)[0, 4]]}"' /etc/passwd
      Or particularly well suited to -a and -F:
      perl -F: -lane 'print "@F[0, 4]"' /etc/passwd

      --
      [ e d @ h a l l e y . c c ]

        Well, if you want to play golf, you can even leave out the spaces:

        perl -F: -lane 'print "@F[0, 4]"' /etc/passwd
        or leave out perl completely:
        cut -d: -f1,5 /etc/passwd|tr : \
        of which the end reminds me to this classic error message:
        $ \(- -bash: (-: command not found