Basically the equivalent of "sort-by" method in CLI.
A sample input file (
one three five eleven thirteen sixteen
Another input file (
file2.txt, which lists length of corresponding line in
3 5 4 6 8 7
Desired output (sort lines in
file1.txt by lines in
file2.txt, in this case numerically; or in other words, sort lines in
file1.txt by the line's length):
one five three eleven sixteen thirteen
I've created a simple Perl script to do this. Sample usage:
% sort-by-lines file1.txt file2.txt % sort-by-lines /etc/passwd <(perl -nE'say length' /etc/passwd)
But was wondering if a combination of more basic Unix commands (
cut, etc) can also do the same in a comparably simple fashion.