>_ IzzyLab

Hands-on task

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

Find lines that are in only one file

medium~5 min

There are two sorted lists of users: /root/all.txt (all) and /root/active.txt (active). Find the users that are in all.txt but absent from active.txt (that is, the inactive ones) and write them to /root/inactive.txt.

What you'll practise:
  • comm
  • sorted files
  • set difference
  • column suppression

Topic breakdown

comm compares two sorted files line by line and outputs three columns: lines only in the first file, only in the second, and common to both. Unwanted columns are suppressed by their numbers via the -1, -2, -3 options, which can be combined. To get "in the first but not in the second" (the set difference), you keep only the first column and turn off the rest.

What's checked

  1. inactive users found

What it looks like