Question

I have a file that has the following IP's:

64.5.12.3
64.5.12.8
122.4.5.1
122.4.5.6

How to unique based on only the first 24 bytes such that, the output is:

64.5.12
122.4.5
Was it helpful?

Solution

Use cut and sort:

cut -c-7 inputfile | sort -u

For your input, it'd produce:

122.4.5
64.5.12

If I understand it correct, you might want to use the following:

cut -d. -f-3 inputfile | sort -u
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top