cut

BSD cut Cheatsheet #

BSD cut is a command-line utility for cutting sections from each line of files, similar to GNU cut but with some differences in options.

Basic Usage #

Command/OptionExampleDescription
cut -f1 -d',' file.txtcut -f1 -d',' data.csvExtract the first field of a comma-separated file
cut -c1-5 file.txtcut -c1-5 textfile.txtExtract the first 5 characters of each line
cut -d':' -f2 file.txtcut -d':' -f2 /etc/passwdExtract the second field from a colon-separated file

Field Separator #

Command/OptionExampleDescription
cut -d',' -f1 file.csvcut -d',' -f1 data.csvSet comma as the field separator and extract the first field
cut -d' ' -f2 file.txtcut -d' ' -f2 textfile.txtSet space as the field separator and extract the second field

Character Positions #

Command/OptionExampleDescription
cut -c1-10 file.txtcut -c1-10 textfile.txtExtract characters from position 1 to 10
cut -c5- file.txtcut -c5- textfile.txtExtract characters from position 5 to the end of the line

Complement #

Command/OptionExampleDescription
cut -d',' --complement -f2 file.csvcut -d',' --complement -f2 data.csvExtract all fields except the second one

This cheatsheet provides essential BSD cut commands for extracting specific parts of text files.

cut

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.