Quiz: Inspecting an archive

Lecture · Exercises

Try each question before opening its hint or answer.


Q1. What differs between unzip -l lab-data.zip and unzip lab-data.zip -d lab-data?

The -l and -d options have different roles.

-l lists entries without extracting them. The second command extracts ordinary files into lab-data. Both leave the ZIP available.


Q2. A manifest has one header line and four sample lines, each ending with a newline. Two samples are labelled treated; the header lacks that word. What do these commands print?

wc -l samples.tsv
grep -F treated samples.tsv | wc -l

The first counts all lines; the second counts only matching lines.

The counts are 5 and 2. Five lines represent four samples plus a header.


Q3. In a practice manifest, S01 is untreated, S03 and S04 are treated, and S02 is control. How many records match grep -F treated? Are they all treated samples?

Literal text matching also finds a search word inside a longer word.

Three records match: S01, S03, and S04. untreated contains treated, so a text match is not the same as selecting a treatment category.


Q4. What does grep -F treated samples.tsv > treated-samples.txt change if the destination already exists?

Consider both the input and the redirection destination.

It replaces treated-samples.txt with the matching lines. The distinct input samples.tsv stays unchanged. Redirection needs a separate destination because > can truncate a file before reading starts.


Q5. The manifest names measurements/S04.csv, but a practice copy contains S04-renamed.csv. What evidence would support restoring its name?

A similar filename alone does not prove sample identity.

In this exercise the rename was deliberate and known. Check the file’s recorded sample ID and 39.8 mm measurement against the source, restore S04.csv, and recheck the manifest path. An unexplained discrepancy would need source evidence.


Q6. The organic-laboratory inventory has a header and four sample rows; O02 and O03 are labelled ester, and no other line contains that word. What does grep -F ester inventory.tsv | wc -l print, and what has grep selected?

The pipe counts the matching lines.

2. grep selected the lines whose text contains ester; the chemical class comes from the supplied labels, not from grep.