EN
Bash - cut examples
8
points
Using cat method we are able to split rows to columns and select some of them.
Examples:
1. Opening passwd file and cutting first column by colon delimiter:
$ cut -d ':' -f 1 /etc/passwd
Note: columns counting from 1.
2. Example 1st with output redirection:
cat /etc/passwd | cut -d ':' -f 1
3. It is possible to select columns (1st and 2nd):
cat /etc/passwd | cut -d ':' -f 1,2
4. We can select column range (from 1st to 3rd):
cat /etc/passwd | cut -d ':' -f 1-3
5. We can select column range (from beginning to 3rd):
cat /etc/passwd | cut -d ':' -f -3
6. We can select column range (from 2nd to end):
cat /etc/passwd | cut -d ':' -f 2-
7. We can precise that we want to interpret only characters:
cut -c 2-7 /etc/passwd
cut -c -7 /etc/passwd
cut -c 2- /etc/passwd
8. We can precise that we want to interpret bytes:
cut -b -10 /etc/passwd
References: