Cut command in Linux (cut by columns)
Your most frequent options are:
- -b number: Prints a vertical list with the number byte (from left to right);
- -c number: Prints a vertical list with the number character (from left to right);
- -d delimiter: Configures the delimiter that separates one column from another. The default is the Tab;
- -f number: Prints column number.
Examples:
To get only user account logins from the /etc/passwd file, using cut. In this case the delimiter will be the “:” and the first column.
$ cut —d”:” -f 1 /etc/<a data-id="762" data-type="post" href="https://www.linuxcertification.academy/basic-security-and-identification-of-user-types-basic-guide/">passwd</a>
To take just the first byte of the /etc/passwd file:
$ cut —b 1 /etc/passwd
To get group names:
$ cat /etc/group | cut -f1 -d': '
The cut command works just like the awk command. The following example produces the same result as the previous command:
$ <a data-id="396" data-type="post" href="https://www.linuxcertification.academy/awk-command-on-linux-processes-data-basic-guide/">awk</a> -F': '' {print $1} '/etc/group