- EXIT CODES
- SEE ALSO
- COPYRIGHT AND LICENSE
sort-by-lines - Sort lines of text by other lines of text as keys
This document describes version 0.002 of sort-by-lines (from Perl distribution App-SortByLines), released on 2019-05-18.
% sort-by-lines [OPTION]... FILE1 FILE2
% sort-by-lines file.txt <(perl -nE'say length' file.txt)
You can use
"-" (in at most one of the files) to mean standard input. Tip: You can use process substitution in bash.
Sample input file file.txt:
one two three four
one two four three
This utility sorts lines of text by other lines of text as keys.
0 on success.
1 on I/O error.
99 on command-line options error.
Please visit the project's homepage at https://metacpan.org/release/App-SortByLines.
Source repository is at https://github.com/perlancar/perl-App-SortByLines.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-SortByLines
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Unary sort or "sort by" implementations in other languages like Perl 6, Python, etc.
Unix command sort, particularly the
--key) option. To do a schwartzian transform on the command-line, using the Tab character to separate the key and value (meaning Tab character in FILE2 will confuse the result):
% paste FILE2 FILE1 | sort -s -k1,2n | cut -f2-
Also notice the use of
--stable) option to preseve the order of lines of the same length. Thanks to Ed Morton for the above tip (https://stackoverflow.com/questions/56200144/how-to-sort-lines-of-text-by-other-lines-of-text-as-keys/56200757).
This software is copyright (c) 2019 by email@example.com.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.