How to find the particular text stored in the file "data.txt" and it occurs only once
To provide some context (I need more rep to comment) this is a question that features in an online "wargame" called Bandit that involves using the command line to discover passwords on an online Linux server to advance up the levels.
For those who would like to see data.txt in full I've Pastebin'd it here however it looks like this:
NN4e37KW2tkIb3dC9ZHyOPdq1FqZwq9hjpEYciZvDIs6MLPhYoOGWQHNIoQZzE5q3rpovhi1CyT7RUTunW30goGek5Q5Fu66JOaWd4uAPii4Jc19AP2McmBNRzBYDAkOJOaWd4uAPii4Jc19AP2McmBNRzBYDAkO9WV67QT4uZZK7JHwmOH0jnhurJMwoGZUa2GjmWtTe3tTM0ARl7TQwraPGXgfkH4f7yJ8imXc7NNiovDuAl1ZC6xb0O0mMBx1UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhRFcOJhZkHlnwqcD8QbvjRyn886rCrnWZ7E3ugYDa6Wh2y8C8xQev7vOS8O3OgG1HwE3ugYDa6Wh2y8C8xQev7vOS8O3OgG1HwME7nnzbId4W3dajsl6Xtviyl5uhmMenvJ5lN3Qe4s7ktiwvcCj9ZHWrAJcUWEhUqaouHvjzagN8QT2BCMB6e9rlN4ffqZ0QqZRF5dlSuwuVV9TLhHKvPvRDrQ2L5ODfD9ZjR3NTHue4YR6n4DgG5e0qMQcJjTaiMQT8Bw9ofH4x3MeRvYAVbYvV1e1zq3Ximi6A6TL6nqvjCAPvOdXZWjlYgyvqxmB7ktx7tQ6kgeJnC446CHbiJY7fyRwrwuhrs
One way to do it is to use:
sort data.txt | uniq -u
The sort
command is like cat in that it displays the contents of the file however it sorts the file lexicographically by lines (it reorders them alphabetically so that matching ones are together).
The |
is a pipe that redirects the output from one command into another.
The uniq
command reports or omits repeated lines and by passing it the -u
argument we tell it to report only unique lines.
Used together like this, the command will sort data.txt lexicographically by each line, find the unique line and print it back in the terminal for you.