Cutting sections of text files (cut command)
Use the cut command to write selected bytes, characters, or fields from each line of a file to standard output.
See the following examples:
- To display several fields of each line of a file, type the following:
This displays the login name and full user name fields of the system password file. These are the first and fifth fields (-f1,5) separated by colons (-d:).cut -f1,5 -d: /etc/passwd
- If the /etc/passwd file looks like this:
the cut command produces:su:*:0:0:User with special privileges:/:/usr/bin/sh daemon:*:1:1::/etc: bin:*:2:2::/usr/bin: sys:*:3:3::/usr/src: adm:*:4:4:system administrator:/var/adm:/usr/bin/sh pierre:*:200:200:Pierre Harper:/home/pierre:/usr/bin/sh joan:*:202:200:Joan Brown:/home/joan:/usr/bin/sh
su:User with special privileges daemon: bin: sys: adm:system administrator pierre:Pierre Harper joan:Joan Brown