0

I have a list of subnets for eg.

180.151.96.0/22
180.151.240.0/21
119.82.112.0/22
203.122.29.0/24
203.122.48.0/22
119.82.92.0/24
180.151.108.0/23
119.82.124.0/24
119.82.89.0/24
180.151.17.0/24
119.82.85.0/24
203.92.59.0/24
125.63.90.0/24
180.151.2.0/24
125.63.126.0/24

The output of these after using sort -n or sort -g is

119.82.112.0/22
119.82.124.0/24
119.82.85.0/24
119.82.89.0/24
119.82.92.0/24
125.63.126.0/24
125.63.90.0/24
180.151.108.0/23
180.151.17.0/24
180.151.2.0/24
180.151.240.0/21
180.151.96.0/22
203.122.29.0/24
203.122.48.0/22
203.92.59.0/24

I need the output as

119.82.85.0/24
119.82.89.0/24
119.82.92.0/24
119.82.112.0/22
119.82.124.0/24
125.63.90.0/24
125.63.126.0/24
180.151.2.0/24
180.151.17.0/24
180.151.96.0/22
180.151.108.0/23
180.151.240.0/21
203.92.59.0/24
203.122.29.0/24
203.122.48.0/22

Such output is only possible using Notepad++ feature 'Sort Lines as Integers Ascending'

Can someone please help :)

1 Answer 1

2

With GNU tools, use sort -V for a "natural sort".

1
  • Thanks.. It worked
    – ph3ro
    Commented Jun 16, 2022 at 17:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .