hns - human numeric sort
hns < input [> output] |
||
hns < <(...) [> output] |
||
... | hns [> output] |
Note:
The name of the command varies — there are also
hns+ and hxs. See SYMLINKS.
A "human numeric" sorting program — does what sort -h is supposed to do!
(That is to say, it does what you likely already thought or may’ve assumed GNU/BSD sort -h does.)
-h, --help
Print help information
-V, --version
Print version information
find . | hns
Numerically sort the names of the files in the current directory.
hns < <(dig peeweeharms.hk)
Numerically sort the IP addresses in the output of dig.
1
seq 0 1000
|
xargs -I{} bash -c "echo {{}} > {}"
2
seq 0 1000
|
awk ’{printf "mv %s topsecret_%s.json\n", $0, $0}’
|
3
parallel
4
paste <(seq 0 1000) <(hns < <(echo
topsecret_[[:digit:]]*.json))
|
awk ’{mv %s topsecret_%04d.json\n", $2, $1}’ | parallel
Use as part of a pipeline to fix accidentally unzeropadded numbers :-)
↓
1 |
write some top secret JSON-format files as 0..=1000 | ||
2 |
move them to .json file extensions | ||
3 |
oops! forgot to zeropad!! managing these files will suck now :-( | ||
4 |
luckily we have hns! |
When run as hns+, negative numbers are not considered. This is ever so slightly faster. When run as hxs, hexadecimal numbers are sorted appropriately (but "negative hexadecimals", a seemingly? useless concept, ignored).
https://github.com/ctrlcctrlv/humnumsort
Fredrick Brennan, humnumsort Project Authors