Linux cut Command
The Linux cut command is used to display text from each line starting from position num1 to num2.
Syntax
cut [-bn] [file]
cut [-c] [file]
cut [-df] [file]
Usage Instructions:
The cut command cuts out sections from each line of files and writes them to the standard output.
If the File parameter is not specified, the cut command reads from the standard input. One of the -b, -c, or -f flags must be specified.
Parameters:
-b : Cuts by bytes. These byte positions ignore multibyte character boundaries unless the -n flag is also specified.
-c : Cuts by characters.
-d : Custom delimiter, default is tab.
-f : Used with -d, specifies which field to display.
-n : Prevents splitting multibyte characters. Only used with the -b flag. If the last byte of a character falls within the range specified by the -b flag's List parameter,
Example
When you execute the who command, it outputs content similar to 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, we do this:
$ who|cut -b 3
c
c