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

Please help, this is a question.

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

I need to find this password. how do i do this using linux?

+4
source share
8 answers

It's a little old, but I think you're looking for this ...

cat data.txt | sort | uniq -u 

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

+13
source

To provide some context (I need more comments for comments), this is a question that has a built-in online version of Wargame called Bandit , which includes using the command line to find passwords on a Linux online server to level it up.

For those who would like to see data.txt in full, I Pastebin'd it here , but 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 this is to use:

 sort data.txt | uniq -u 

The sort command is similar to cat because it displays the contents of the file, however it sorts the file lexicographically by lines (it reorders them alphabetically so that the matching ones coincide).

| is a channel that redirects output from one command to another.

The uniq command reports or omits duplicate lines and passes it the -u argument, which we tell it to only report unique lines.

Used along with this, the command will sort data.txt lexicographically for each line, find a unique line and print it back in the terminal for you.

+4
source

Below you will get what you need.

 grep 'password' data.txt 
+1
source

Add more information to you. What does data.txt look like? Like this:

 11111111 11111111 pass1111 11111111 

Or like that

 afawfdgd password somethin gelse... 

And did you know that the password is in the file, or you are looking for a string with repetition.

If you know the password, use something like this

cat data.txt | grep 'password'

If you do not know the password, and this password is a unique line in the file, you must create a script. For example, in Python

 file = open("data.txt","r") f = file.read() for line in f: if 'pass' in line: print pass 

Of course, replace the passage with another. For example, some slice from a string.

+1
source

Does it help?

cat data.txt | grep password

0
source

sort -u data.txt | when reading a line; do if [$ (grep -c $ line data.txt) == 1], then echo $ line; Fi done

was my decision until I saw a lung here

sort data.txt | uniq -u, tnx

0
source

sort data.txt | uniq -c | grep 1\ ?*

and it will print only the text that appears only once do not forget to put a space after the backslash

0
source

And one using only one tool, awk :

 awk '{a[$1]++}END{for(i in a){if(a[i] == 1){print i} }}' data.txt 
0
source

Source: https://habr.com/ru/post/1438416/


All Articles