Signal9Signal9 — home
online
back to labs

Filter Pipeline: Ranges, Filters and :r !cmd

MediumText Editors15-25 min
The brief

/root/case/inventory.cfg has a hosts block between the lines # BEGIN hosts and # END hosts. It's a mess: mixed case, duplicates (some differ only in case), trailing spaces and no order. The hosts and the release differ per session.

Edit the file in place:

1. Normalise only the hosts block: one host per line, lowercase, no leading or trailing whitespace, no duplicates, sorted. Keep both marker lines. Every line outside the block must stay exactly as it is.

2. Directly below the line # release digest:, insert the SHA-256 of /root/case/release.tar as one line, either the bare 64-hex digest or the line sha256sum prints for it.

In vim this is a range (:/BEGIN/+1,/END/-1) used with a substitute or two and a filter through sort -u, plus :r !sha256sum … for the digest. Grading reads the file, so any tool is accepted.

What you'll do
  • Address a block of lines with a pattern range
  • Filter a range through an external command
  • Change case and trim whitespace with substitutions
  • Read a command's output into a file with :r !cmd

Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.