If you have a file that consists of lines of text that are split into fields by white space or a delimiter character, cut can get a particular field or fields from every line of the file. For example, in /etc/passwd the file is delimited by the colon character (:). The cut option, -f, tells it which field or fields you are selecting, and the -d option tells it what the delimiter character is. The file /etc/passwd is made up of lines like this:
To get just the real name (the fifth) and the shell (the seventh) fields from the file, you could do this:
This would produce many lines of output like this:
You can also select particular characters from each line, using the -c option as follows:
Was this article helpful?