The Linux cut command is used to display the text from num1 to num2 in each line starting from the beginning.
Syntax
Cut [-bn] [file]
Cut [-c] [file]
Cut [-df] [file]
Instructions for use:
The cut command cut bytes, characters, and fields from each line of the file and writes these bytes, characters, and fields to the standard output.
If the File parameter is not specified, the cut command reads the standard input.
-B,-c, or-f must be specified.
Parameters:
- -B: Split in bytes. These byte locations ignore the multi-byte character boundary unless the-n flag is also specified.
- -C: separated by characters.
- -D: custom delimiter. The default delimiter is tab.
- -F: used with-d to specify the region to display.
- -N: undelimiter multi-byte characters. It is used only with the-B flag. If the last byte of a character falls within the range indicated by the-B Mark List parameter, the character is written out; otherwise, the character is excluded.
Instance
When you execute the who command, the output is similar to the following:
$ Who
Rocrocket: 0
Rocrocket pts/0 (: 0.0)
Rocrocket pts/1 (: 0.0)
If we want to extract the 3rd bytes of each row, it will be like this:
$ Who | cut-b3
C
C