@jschauma GNU sort will do this with -V 'version' number sorting, which can be used on any field AFAIK. I think FreeBSD sort also has a -V option that behaves enough like this to work for IPv4 addresses.
Conversation
Notices
-
Embed this notice
Chris Siebenmann (cks@mastodon.social)'s status on Saturday, 23-Mar-2024 03:04:27 JST Chris Siebenmann - Haelwenn /элвэн/ :triskell: likes this.
-
Embed this notice
Jan Schaumann (jschauma@mstdn.social)'s status on Saturday, 23-Mar-2024 03:04:28 JST Jan Schaumann Today in stupid #unix #shell games: sorting by numeric IPv4 address
Input: a file with '|' separated fields with IPv4 addresses in the third field
awk -F'|' '{print $3 "%" $0 }' | # pull the address to the front \
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n | # numerically sort each octet in order \
sed -e 's/^.*%//' # strip the leading field again