User Tools

Site Tools


ubuntu:bash:cut

This is an old revision of the document!


Ubuntu - Bash - cut

cut - remove sections from each line of files

cut can return section based on number of bytes (-b), characters (-c), or fields (-f) when fields are separated by a delimiter(-d).

Default delimiter is tab.


A range must be provided in each case which consists of one of N, N-M, N-(N to last) or -M (first to M)

cut -c 2-4
abcdef

Press CTRL+D to stop inputting

returns:

bcd

cut -c 3

abcdef c

cut -c 2,4,7

alongtext lne

cut -c -2

abcdef ab

cut -c 2-

abcdef bcdef

cut -c 1,6-9,16-

alongtextwithnospaces atextspaces

cut -f 2- -d ':'

23:34:45:56 NOTE: -d specifies delimiter 34:45:56

cut -f 2

er rt fg wd ji er rt fg wd ji

NOTE: cut didn't find the delimiter (default is tab) so returns whole line.

cut -f 2 -s

er rt fg wd ji

NOTE: cut wont print as -s flag is used to prevent printing when delimiter not found.

cut -d: -f1 /etc/passwd >users.txt
ubuntu/bash/cut.1575022136.txt.gz ยท Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki