Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the particular text stored in the file "data.txt" and it occurs only once

Tags:

linux

search

The line I seek is stored in the file data.txt and is the only line of text that occurs only once.

How do I go about finding that particular line using linux?

like image 549
user1565960 Avatar asked Oct 08 '12 13:10

user1565960


2 Answers

This is a little bit old, but I think you are looking for this...

cat data.txt | sort | uniq -u

This will show the unique values that only occur once in the file. I assume you are familiar with "over the wire" if you are asking?? If so, this is what you are looking for.

like image 79
BostonGeorge Avatar answered Oct 02 '22 18:10

BostonGeorge


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:

NN4e37KW2tkIb3dC9ZHyOPdq1FqZwq9h
jpEYciZvDIs6MLPhYoOGWQHNIoQZzE5q
3rpovhi1CyT7RUTunW30goGek5Q5Fu66
JOaWd4uAPii4Jc19AP2McmBNRzBYDAkO
JOaWd4uAPii4Jc19AP2McmBNRzBYDAkO
9WV67QT4uZZK7JHwmOH0jnhurJMwoGZU
a2GjmWtTe3tTM0ARl7TQwraPGXgfkH4f
7yJ8imXc7NNiovDuAl1ZC6xb0O0mMBx1
UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR
FcOJhZkHlnwqcD8QbvjRyn886rCrnWZ7
E3ugYDa6Wh2y8C8xQev7vOS8O3OgG1Hw
E3ugYDa6Wh2y8C8xQev7vOS8O3OgG1Hw
ME7nnzbId4W3dajsl6Xtviyl5uhmMenv
J5lN3Qe4s7ktiwvcCj9ZHWrAJcUWEhUq
aouHvjzagN8QT2BCMB6e9rlN4ffqZ0Qq
ZRF5dlSuwuVV9TLhHKvPvRDrQ2L5ODfD
9ZjR3NTHue4YR6n4DgG5e0qMQcJjTaiM
QT8Bw9ofH4x3MeRvYAVbYvV1e1zq3Xim
i6A6TL6nqvjCAPvOdXZWjlYgyvqxmB7k
tx7tQ6kgeJnC446CHbiJY7fyRwrwuhrs

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.

like image 37
Paul Tibbetts Avatar answered Oct 02 '22 17:10

Paul Tibbetts