The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

sort-by-lines - Sort lines of text by other lines of text as keys

VERSION

This document describes version 0.002 of sort-by-lines (from Perl distribution App-SortByLines), released on 2019-05-18.

SYNOPSIS

 % sort-by-lines [OPTION]... FILE1 FILE2

Sample command:

 % 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

Sample output:

 one
 two
 four
 three

DESCRIPTION

This utility sorts lines of text by other lines of text as keys.

EXIT CODES

0 on success.

1 on I/O error.

99 on command-line options error.

OPTIONS

--ignore-case, -i
--numeric-sort, -n
--reverse, -r

FAQ

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-SortByLines.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-SortByLines.

BUGS

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.

SEE ALSO

https://en.wikipedia.org/wiki/Schwartzian_transform in Perl 5.

Unary sort or "sort by" implementations in other languages like Perl 6, Python, etc.

Unix command sort, particularly the -k (--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 -s (--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).

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.