How TextPipe sorts files that are too big for an editor
Most sort utilities read the whole file into memory first. That works for a 20 MB export, but a 6 GB web server log or a multi-million-row database dump will exhaust RAM, and the tool either stops or starts swapping to disk for hours. TextPipe uses an external merge sort. It reads the input in chunks, sorts each chunk, writes the sorted chunks to temporary files, and then merges them into the final output. Memory use stays small and predictable, and the only real limit is free disk space for the temporary files.
Sorting is rarely just alphabetical order. You may need to sort on a column inside each line, treat numbers as numbers instead of text, ignore upper and lower case, or sort in descending order. You can set these options in the Sort filter. Duplicate handling is part of the same step: TextPipe can discard repeated lines, keep only the lines that appear once, or write each distinct line together with the number of times it occurred.
Sample input and output
Suppose a web log has been reduced to the visitor IP address of each request, and you want a ranked list of the most active addresses. The input contains one address per line, in arrival order:
203.0.113.9
198.51.100.4
203.0.113.9
192.0.2.77
203.0.113.9
198.51.100.4
Sorting with the count-duplicates option, and then sorting the result by count in descending order, produces:
3 203.0.113.9
2 198.51.100.4
1 192.0.2.77
The same two steps run unchanged on a log with 200 million lines. A command line version of the filter set can be scheduled to run each night, so the report is ready every morning.
Typical settings
- Sort key: sort the whole line, or only a column range or delimited field, for example the third comma-separated field of a CSV file.
- Comparison type: choose text, numeric, or case-insensitive comparison. Numeric sorting puts 9 before 10, which text sorting does not.
- Duplicates: keep all lines, remove duplicates, or count them.
- Temporary folder: point it at a fast drive with free space of at least the size of the input file.
Practical applications
Database administrators sort and de-duplicate key lists before a bulk load, because loading sorted data into an indexed table is much faster. Security teams rank failed login attempts by source address. Mailing houses sort name and address files by postal code, and remove repeated records, to qualify for bulk postage discounts. Data analysts sort two extracts on the same key so that differences are easy to compare, or so that the files can be joined line by line.
Common pitfalls
- Sorting numbers as text puts 100 before 20. Use numeric comparison when the key is a number.
- Files with a header row sort the header into the middle of the data. Skip the first line with a line-range filter, or add the header back afterwards.
- Duplicates that differ only by trailing spaces are not treated as identical. Trim the lines first if you want them merged.
Related pages
The sort large files feature guide lists every sort option. Once your data is in order you can join and merge files in a single pass, or convert mainframe EBCDIC files before sorting them. For wider data preparation projects, see the data conversion solutions page and the database consulting case study. Teams that tidy up Word documents as well can use WordPipe for the equivalent batch edits.