>_ IzzyLab

Hands-on task

This task is step 1 of the course “Text in the terminal: grep, sed, awk”

Cut a field by delimiter

easy~2 min

/root/sales.csv is a sales export: fields are separated by a semicolon, and the first line is the header date;manager;region;amount;status. The report needs only the columns manager, region and amount — in the same order, with the same ; delimiter, and together with the header. Write them to /root/report.csv.

What you'll practise:
  • cut
  • field delimiter
  • field selection
  • csv

Topic breakdown

cut extracts individual fields from each line. The field delimiter is set with one option, and exactly which fields to output with another (field numbers, counting from one). For data with a fixed delimiter such as CSV, this is the most direct way to pull out the column you need.

What's checked

  1. report header
  2. report data

What it looks like