← Back to Home

OverTheWire Bandit: Level 8 → Level 9

Technical Note

Context

In Linux, we can use the output of one command as the input for another. This is called Piping, represented by the vertical bar |. This feature is the heart of the Unix philosophy: “Write programs that do one thing and do it well. Write programs to work together.”

In this level, we have a data.txt file containing thousands of lines of text. However, only one line occurs exactly once; all others are repeated.

Goal

Find the single unique line (the password) in data.txt.

Solution

To filter out duplicate lines, we use the uniq command. However, uniq has a catch: It only detects duplicates if they are adjacent (next to each other).

Since our file is scrambled, uniq alone won’t work effectively. We must first verify the data is sorted alphabetically (sort) so that identical lines sit together, and then apply uniq.

This is where the Pipe (|) comes in:

  1. sort data.txt: Sort the file content.
  2. |: Take the sorted output…
  3. uniq -u: …and feed it into uniq. (The -u flag stands for “unique”, printing only lines that appear once).

combining the commands:

sort data.txt | uniq -u

Output:

EN632PlfYiZbn3PhVK3XOGSlNInNE00t

Bingo! Thousands of duplicate lines are filtered out, leaving only the unique password.

Key Takeaways

  1. Piping (|): Allows chaining commands. The output of the left command becomes the input of the right command.
  2. sort: Sorts data alphabetically or numerically.
  3. uniq: Filters duplicate lines. Almost always used after sort. The -u flag shows only unique lines, while -c (count) counts occurrences.