Count lines
User rung6
ssh -p 2222 rung6@play.ctf.wail.ly
Goal
votes.txt contains thousands of lines. The password for the next level is the line that appears most often.
Commands that may help
sortuniqtail
Reading
man sort: sorting lines, and the option-n, which sorts by number.man uniq: the option-c, which counts repeated lines.
Prerequisite: not tied to a lecture chapter.
Hints
Hint 1
Counting by eye is hopeless. Identical lines are much easier to count once they sit next to each other, and
sort puts the lines of a file in order. You can chain several commands: the pipe | sends what one command prints into the next one instead of to the screen.Hint 2
uniq -c merges each run of identical neighbouring lines into a single line, with the number of copies written in front. It only compares a line with the one just before it, which is why the lines must be sorted first.Hint 3
Chain four commands with pipes
|, in this order. sort followed by the file name puts the lines in order. uniq with the option -c then prints each distinct line once, with its count in front. sort again, this time with the option -n, orders those lines by count, so the largest count comes last. Finally tail with the option -n and the number 1 keeps only that last line. The password is the text after the count on that line.