Project Home

sort-order

Table of Contents

Description

Sort lines according to an arbitrary list of ordering string prefixes.

The idea is that sometimes we want a list of strings ordered according to an arbitrary ordering. This program will read a file that specifies a list of prefixes and that will then sort the given input lines according to the order of the arbitrary list of prefixes, by attempting to match the prefixes to the input lines.

The ordering file is compulsory and must be specified. It simply contains one string per line which is assumed to be a prefix for the lines to be sorted by.

Note that strings to be sorted which cannot be sorted because they don't match any prefix from the ordering file will be placed at the end of the list with special markers. There are options to alter this behaviour.

Use Case

This script was originally created to sort a list of filenames in compilation order. A special target in the makefiles would simply generate to a file the list of directories to be compiled, in compilation order. Then that file was used as the ordering file on an arbitrary list of source files (we were performing diffs for merge review, but we wanted the diffs to show up in compilation order).

Usage

sort-order <order-file> [<unsorted-file> ...]

Please Donate!

Important

This computer program or library is provided for free. I am aware that some of the programs that I provide for free allow people to get their work done faster or better, save them time and money. If you are using this program for benefit, especially if you are using it within a commercial environment and it saves you time or work, please consider making a donation by sending me a book from my Amazon Wishlist or by a direct donation to my company's PayPal account by clicking on the link below.

Download

Download program here.