SEARCH THE LAB

What are you looking for?

SkillsReview information not provided

Before compressing, split records into a skeleton and variables

Review information not providedAdded to the lab: 26 November 2026

Many people assume that if a file contains a lot of repeated content, compression is bound to shrink it. Real experience is often the opposite: a log file or…

Added to the lab
Downloads
0
Human review
Review information not provided

Many people assume that if a file contains a lot of repeated content, compression is bound to shrink it. Real experience is often the opposite: a log file or an exported table that looks largely identical may compress to something close to its original size. One reason is that general-purpose compressors only look for repeats within a limited sliding window, and the repeats in such files are often far apart, or broken up by constantly changing fields.

One practical small technique: before compressing, split the records into a fixed skeleton and changing values, then handle each part separately. Store the skeleton only once, and store the changing values in separate columns by field. The point is not to invent your own compression algorithm, but to turn the long-distance repetition that compressors handle poorly into the short-distance repetition they handle well.

The steps can go like this.

Step one: sample and confirm the file can be parsed. Take a small excerpt from similar files awaiting archiving, and look at a dozen records by hand to confirm that field boundaries are stable: whether delimiters are consistent, whether any records span lines, whether there are quote escapes. If the boundaries are not stable, do not split yet; splitting wrong causes more trouble than not splitting.

Step two: write the template. Keep the fixed part of each record and replace the changing parts with placeholders, yielding one skeleton line and a list of fields numbered by position. Save the skeleton once; each field becomes a separate sequence, so that, for example, time, ID, and result each form their own column. For instance, if a batch of records all begin with a timestamp in the same format followed by the same prompt sentence, then the timestamp and the prompt sentence should go into separate columns rather than alternating within the same line.

Step three: store by column. Write each column to its own file. If reordering within a column is acceptable, you can first sort by value so that identical or similar values sit next to each other, and the compressor will face denser repetition. Reordering has a cost: the original order must be recorded separately, usually as a table of row-number permutations, and the order is restored by following it.

Step four: do a round-trip check. Write a restore script, run it first on the small sample just used, and compare the restored result with the original file byte for byte, or verify it with a checksum. Only if they match does it show that the split is lossless. This step cannot be skipped, because if the template leaves out a field, the loss is silent.

Step five: then decide whether to use it for archiving. Compress each split column separately and compare the sizes with compressing the original file directly; if the gain is not obvious, or the maintenance cost of the restore script exceeds the benefit, keep the file as it is. When processing in bulk, validate on a small batch first, then expand to the whole batch, and always keep an unmodified original copy.

A few limitations need to be made clear. This method depends on a stable format: once the upstream changes field order or wording, the old template will no longer match, so templates must follow format versions. If the variable columns contain free text, such as casually written notes, repetition within the column is low and the gain will drop. Splitting itself also requires scripts and an index, so it is not worthwhile for just one or two small files. One more point is easy to overlook: a smaller file does not mean less information; the criterion is always whether the restored version matches the original, not the compressed size.