Languages
[Edit]
EN

Bash - cut examples

8 points
Created by:
Amir-Hashempur
547

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:

  1. https://ss64.com/bash/cut.html
  2. https://en.wikipedia.org/wiki/Cut_(Unix)
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - cut examples
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join