- tye (but my friends call me "Tye")print # 5) Print the sorted lines. map { # 4) Transform lines back to original: my( $co, $ip, $e )= # 4a) Split out the 3 fields split /,/; $ip= join ".", map { # 4b) Remove zero padding from IP addr sprintf "%d", $_ } split /\./, $ip; "$ip,$e,$co\n" # 4c) Restore field order and newline } sort # 3) Sort the transformed data by char. map { # 2) Transform lines so default sort works: chomp; # 2a) Remove trailing newline my( $ip, $e, $co )= # 2b) Split out the 3 fields split /,/; $ip= join ".", map { # 2c) Pad IP addr w/ zeros so sorts OK sprintf "%03d", $_ } split /\./, $ip; "$co,$ip,$e" # 2d) Put fields in the order of sort } <>; # 1) Read in all of the lines.
In reply to (tye)Re: How do I sort a file with IP Addresses and another text column
by tye
in thread How do I sort a file with IP Addresses and another text column
by arv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |