Jan Schaumann on Nostr: Today in stupid #unix #shell games: sorting by numeric IPv4 address Input: a file ...
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
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