cut

What is cut?

cut is implemented in almost all, if not in all distributions of Linux. The main purpose of this tool is to cut text in parts. The source of this text does not mind (source can be a file, or output from another tool).

How to use cut

Be sure to understand the pipe command first

##### cut specific characters
cat /etc/passwd | cut -c 1-10 # cuts the first 10 characters of every line in the file /etc/passwd
cat /etc/passwd | cut -c 1,2,3,4,5,6,7,8,20,21,22 # cuts the lines 1 to 8, 20, 21 and 22

##### cut specific fields
cat /etc/passwd | cut -d : -f 1-3 # cuts the first 3 fields of every line in the file /etc/passwd
cat /etc/passwd | cut -d : -f 1,3,5 # cuts the first fields, third field and fifth field of every line in the file /etc/passwd

cut --version # get the current version of cut

Last updated