Level 8 → Level 9
Completed📋 Level Information
🎯 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.
Challenge: The file contains many duplicate lines. You need to find the single unique line.
🔧 Solution Steps
Step 1: Connect to Bandit8
Use the password from Level 7 to log in:
ssh bandit8@bandit.labs.overthewire.org -p 2220
Password: TESKZC0XvTetK0S9xNwm25STk5iWrBvP
Step 2: Check the data.txt File
First, let's see what we're dealing with:
ls -lh data.txt
head data.txt
You'll see the file contains many lines, most of which are duplicates.
Step 3: Sort and Find Unique Lines
Use sort and uniq commands to find the line that appears only once:
sort data.txt | uniq -u
Command breakdown:
sort- Sorts the lines alphabeticallyuniq -u- Shows only unique lines (that appear exactly once)|- Pipe sends output from sort to uniq
Step 4: Get the Password
The command will output the single unique line, which is the password for Level 9:
EN632PlfYiZbn3PhVK3XOGSlNInNE00t
🔄 Alternative Methods
Method 2: Using uniq with count
First show all lines with their counts, then find the one with count 1:
sort data.txt | uniq -c | grep "1 "
This shows the count before each line and filters for lines that appear once.
Method 3: Using awk
You can use awk to count occurrences and print unique lines:
awk '{count[$0]++} END {for (line in count) if (count[line] == 1) print line}' data.txt
Method 4: Step by step verification
If you want to see the intermediate steps:
# See sorted output
sort data.txt
# See lines with counts
sort data.txt | uniq -c
# Find the line with count 1
sort data.txt | uniq -c | grep -w 1
💡 Explanation
This level teaches text processing with sort and uniq commands to find unique entries in data.
sort Command:
- sort - Arranges lines in alphabetical or numerical order
- Required before using uniq because uniq only compares adjacent lines
- Makes duplicate lines appear next to each other
uniq Command Options:
- uniq -u - Shows only unique lines (appear exactly once)
- uniq -d - Shows only duplicate lines (appear more than once)
- uniq -c - Shows counts before each line
- uniq -i - Case insensitive comparison
Why Sorting is Necessary:
- uniq only compares adjacent lines in the input
- Without sorting, duplicates might not be next to each other
- Sorting groups all identical lines together
⚠️ Common Mistakes
- Forgetting to sort: Using uniq without sort first
- Wrong uniq option: Using -d instead of -u
- Case sensitivity: Lines with different cases are considered different
- Whitespace: Extra spaces can make lines appear different
💡 Pro Tips
- Use
sort -uto remove duplicates (simpler alternative to sort | uniq) - Combine with
wc -lto count unique lines:sort data.txt | uniq | wc -l - Use
uniq -ifor case-insensitive comparison - You can sort numerically with
sort -n - Reverse sort with
sort -r