bash:cut
This is an old revision of the document!
Table of Contents
BASH - cut
The cut command allows cutting of sections based on byte positions, characters, or fields separated by a delimiter like the ‘-‘ or ‘:’ characters.
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.
Field Cuts
Cut fields from a string, using a delimiter
cut -f 2- -d ':' 23:34:45:56
NOTE: -d specifies delimiter
returns:
34:45:56
Cut fields from a string, without specifying a delimiter
cut -f 2 er rt fg wd ji
returns:
er rt fg wd ji
NOTE: cut didn't find the delimiter (default is tab) so returns whole line.
Cut fields from a string, without specifying a delimiter; and prevent printing when delimiter not found
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 fields from a file, using a delimiter
cut -d: -f1 /etc/passwd >users.txt
bash/cut.1576189860.txt.gz · Last modified: 2020/07/15 09:30 (external edit)