>_ IzzyLab

Hands-on task

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

Order export without cancelled orders

easy~3 min

The export /root/orders.csv (a header and lines id,client,amount,status) contains cancelled orders with the status cancelled. Keep in /root/active_orders.csv all lines except the cancelled ones — together with the header and in the original order.

What you'll practise:
  • grep -v
  • inverted match
  • line filtering
  • csv

Topic breakdown

It's often easier to describe what to throw away than what to keep. For that grep has the -v inversion: it prints the lines where the pattern is not found, in the original order. The pattern can be a plain word — it has no metacharacters, and extended mode isn't needed. If the word might also appear in another column (say, in a comment), the pattern is made more specific — for example, anchored to the end of the line with $.

What's checked

  1. no cancelled orders
  2. header and the other orders are in place

What it looks like