DEV Community

CTFDojo
CTFDojo

Posted on Originally published at ctfdojo.com

OverTheWire Bandit Level 8 Writeup — Find the One Unique Line Among Duplicates

The password is the one line in data.txt that occurs exactly once among thousands of duplicated lines — sort groups identical lines together, and uniq -u prints only the ones with no duplicate.

  • Platform: OverTheWire Bandit
  • Category: Linux Fundamentals
  • Level: 8 → 9
  • Difficulty: Beginner
  • Technique: sort + uniq -u

Challenge description

Level 8 hands you a file where almost every line of text shows up more than once. Somewhere in there is exactly one line that appears only a single time — that line is the password.

"Level Goal: The password for the next level is stored in the file data.txt and is the only line of text that occurs only once."

Step 1 — Understand why uniq alone won't work

uniq only collapses consecutive duplicate lines — it has no effect on a file where duplicates are scattered throughout rather than grouped together. The file needs to be sorted first so every copy of a given line ends up adjacent to its other copies.

Step 2 — Sort the file

Sorting brings every duplicate of a line next to each other, which is the precondition uniq needs to do anything useful:

sort data.txt | less
Enter fullscreen mode Exit fullscreen mode
(every line now appears grouped with its exact duplicates)
Enter fullscreen mode Exit fullscreen mode

Step 3 — Filter to lines with no duplicate

uniq's -u flag prints only the lines that have exactly one occurrence — exactly the property the level described:

sort data.txt | uniq -u
Enter fullscreen mode Exit fullscreen mode
[PASSWORD FOR bandit9]
Enter fullscreen mode Exit fullscreen mode

🔑 password intentionally hidden

The password is deliberately hidden — follow the method, you've earned it. 💪

Key takeaways

sort and uniq are almost always used together, because uniq only ever looks at immediately adjacent lines. "Find the duplicate" or "find the one that's NOT duplicated" in a scrambled file is a sort | uniq problem essentially every time.

  • uniq collapses or isolates duplicates among ADJACENT lines only — unsorted input defeats it silently
  • sort groups every copy of an identical line together, which is why it always comes first in this pipeline
  • uniq -u prints lines with no duplicate at all; plain uniq -d does the opposite, printing only lines that DO repeat

Originally published on CTFdojo — join the CTFdojo Discord to discuss writeups and get notified about new ones.

Top comments (0)