A
A
Alexey Yarkov2017-01-19 14:09:13
bash
Alexey Yarkov, 2017-01-19 14:09:13

How to store the port number in this case?

There is a file with proxies (example):

127.0.0.1:8081
127.0.0.1:878
127.0.0.1:80
137.30.30.1:8080
137.30.30.1:80
127.0.0.1:878
137.30.30.1:8080

Sorting:
$ cat test.txt | sort -u
127.0.0.1:80
127.0.0.1:8081
127.0.0.1:878
137.30.30.1:80
137.30.30.1:8080

The result is expected, but not what is needed.
Let's try it differently:
$ cat test.txt | awk -F  ":" ' { print $1 } ' | sort -u
127.0.0.1
137.30.30.1

What you need! Only unique IPs remain, but.... No port numbers! How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mureevms, 2017-01-19
@mureevms

cat test.txt | sort -u | uniq

X
xibir, 2017-01-19
@xibir

sort -k1 -t: < 1.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question