cut
purpose: remove sections from lines within files
example file, message.txt:
example, print the first character of a file:
cut -b 1 message.txt
-b: select by byte
-c: select by character
-d: select by delimiter
-f: select by field
example, print the first character of a file:
cut -b 7,8,9,10,11 message.txt
better, if the characters are sequential:
cut -b 7-11 message.txt
more consistently (to avoid if a character takes more than 1 byte),
cut -c 7-11 message.txt
example: choose multiple character intervals:
cut -b 7-11,56,57-61 message.txt
example, split a file by field:
by default, tab \t is the delimeter.
change the delimeter to space instead:
cut -d " " -f 1,2 message.txt
example: extract usernames
cat /etc/passwd
cut -d ":" -f 1 /etc/passwd
cut is best used on files with multiple rows and fields