0

I'd like to know how cat passwd | awk -F':' '{printf $1}' works. cat /etc/passwd is a list of users with ID and folders from root to the current user (I don't know if it has something to do with cat passwd). -F is some kind of input file and {printf $1} is printing the first column. That's what I've search so far but seems confusing to me.

Can anyone help me or explain to me if it's right or wrong, please?

b4hand
  • 9,550
  • 4
  • 44
  • 49
Sean Sabe
  • 79
  • 9
  • Right or wrong? According to what? – Maroun Nov 22 '14 at 21:50
  • Among other things, it assumes you're currently in the `/etc` directory, or that there's a `passwd` file in your current directory. If you really want the system password file, use the full pathname `/etc/passwd`. It won't show all user names if the system uses a mechanism other than `/etc/passwd` such as NIS or LDAP. All these commands are very well documented; `man awk` would have told you exactly what `-F` means (it's not "some kind of input file"). – Keith Thompson Nov 22 '14 at 22:17
  • @MarounMaroun The command. – Sean Sabe Nov 23 '14 at 02:45
  • I don't mean to be rude but you are SO far off on all counts you need to find some kind of "intro to UNIX" tutorial and work your way through that. – Ed Morton Nov 23 '14 at 14:49

1 Answers1

1

This is equivalent to awk -F: '{print $1}' passwd. The cat command is superfluous as all it does is read a file.

The -F option determines the field separator for awk. The quotes around the colon are also superfluous since colon is not special to the shell in this context. The print invocation tells awk to print the first field using $1. You are not passing a format string, so you probably mean print instead of printf.

b4hand
  • 9,550
  • 4
  • 44
  • 49