How to use -f option?

The -f option in the cut command is used to specify the fields to extract from each line of input, based on a delimiter. By default, the delimiter is a tab character, but you can change it using the -d option.

Example Usage:

  1. Using Default Tab Delimiter:
cut -f1 filename.txt

This command extracts the first field from each line of filename.txt, assuming fields are separated by tabs.

  1. Using a Custom Delimiter:

If your fields are separated by a different character, such as a comma, you can specify that with the -d option:

cut -d',' -f2 filename.txt

This command extracts the second field from each line of filename.txt, where fields are separated by commas.

  1. Extracting Multiple Fields:

You can also extract multiple fields by specifying a comma-separated list or a range:

cut -d',' -f1,3 filename.txt

This extracts the 1st and 3rd fields.

cut -d',' -f1-3 filename.txt

This extracts the first three fields.

0 Comments

no data
Be the first to share your comment!