Today I had to import about ~150 file entries into an XML file. Being a good lazy geek, I could not resign myself to copy/paste this over. With the help of Rake and some custom-tailored scripts, I made it through in no time :)
All these files had the same format:
1 2 3 4 5 |
|
Of course, when I tried to sort them with the sort
command, it did not really work as expected… Because this is a lexicographical sort, and not the natural sort we would expect.
1 2 |
|
I needed a natural sort, just like the natsort() function from PHP. Actually, I also needed a small program that would list the contents of a directory and print its naturally-sorted contents.
These scripts are available on my github. You can easily install them for your user by running the shutil_install.sh
script. You may have to chmod +x
the scripts however. Read more on these scripts on their dedicated page.
Hope you’ll find this useful, feel free to contribute your own scripts (via pull requests, for example :)