Linux cut command
The Linux cut command is used to display the text of each line from num1 to num2, counting from the beginning.
Syntax
cut [-bn] [file]
cut [-c] [file]
cut [-df] [file]
Usage:
The cut command cuts bytes, characters, and fields from each line of a file and writes them to standard output.
If the File argument is not specified, cut reads from standard input. You must specify one of the -b, -c, or -f flags.
Parameters:
- -b: Split by bytes. These byte positions will ignore multibyte character boundaries unless the -n flag is also specified.
- -c: Split by characters.
- -d: Custom delimiter; the default is tab.
- -f: Used with -d to specify which field to display.
- -n: Do not split multibyte characters. Used only with the -b flag. If the last byte of a character falls within the
range indicated by the List argument of the -b flag, the character will be written out; otherwise, it will be excluded
Example
When you run the who command, it outputs something like the following:
$ who
rocrocket :0 2009-01-08 11:07
rocrocket pts/0 2009-01-08 11:23 (:0.0)
rocrocket pts/1 2009-01-08 14:15 (:0.0)
If we want to extract the third byte of each line, do this:
$ who|cut -b 3
c
c
Linux Command Reference