Bandit Walkthrough – Level 8
Level Description
http://www.overthewire.org/wargames/bandit/bandit9.shtml
The purpose of this level is to teach you how to search through a file for a unique string. The password for bandit9 is hidden in the file data.txt and is the only line of text that occurs only once
Hint
This will require two commands, one to sort the contents of the file, and another to display only strings that are not duplicated. You will need to join these commands using a pipe (|) character.
Solution | Show> |
---|---|
Why should it be sorted before piping into uniq, why doesnt uniq -u data.txt work?
Because Uniq compares consecutive strings only
uniq only filters out lines that are adjacent
it is because the uniq command only work on adjacent lines.
The uniq command only detects adjacent repeated lines. In the document the repeated lines are not necessarily next to each other, in which case the uniq command will not detect them. By using the sort command, all of the repeated lines will be arranged such that they are adjacent to each other.
uniq does not detect duplicates that are not adjacent. So it will not detect duplicates in the following example:
a
b
a
However, using the sort command first will make any duplicates adjacent (as in the following example) and thus uniq will detect them:
a
a
b
Awesome forum! Thanks for the knowledge!