Nhảy tới nội dung

cut

Intro

cut is a powerful command for isolating texts in formatted document, especially csv files.

Syntax: cut [option] file

Basic usage

cut
$ cat server.csv
ID,Name,Status,Networks
2a304fe9-82cc-4948-ae1b-c31e07c9e40b,test-thinhdp,ACTIVE,192.168.1.29
990fdc8d-08fe-47da-a555-9576940a4846,test-tritn,ACTIVE,192.168.1.28
3b56ea2f-03e6-45fb-b0c5-60475f97067e,test-sang,SHUTOFF,192.168.1.62

$ cut -d':' -f2 server.csv
net-2:/tmp$ cut -d "," -f2 server.csv
Name
test-thinhdp
test-tritn
test-sang
# -d: dilimiter used for separated fields
# -f: the field that we want to pick after separated

# -c for character isolating
$ cut -c 1-36 server.csv # get first 36 char
ID,Name,Status,Networks
2a304fe9-82cc-4948-ae1b-c31e07c9e40b
990fdc8d-08fe-47da-a555-9576940a4846
3b56ea2f-03e6-45fb-b0c5-60475f97067e