Handle Lines with Different Lengths

Process fixed-width files where lines have varying lengths. Learn how short lines are handled and how to avoid truncation errors.

Auto-Detection

Detailed Explanation

Variable-Length Lines in Fixed-Width Files

While fixed-width files ideally have uniform line lengths, real-world data often has lines of different lengths — due to trailing whitespace stripping, optional fields at the end of a record, or mixed record types.

Common Scenarios

Trailing spaces stripped:

John      Smith     New York
Jane      Doe       LA
Bob       Johnson

Line 3 is shorter because the city field was empty and trailing spaces were stripped during file transfer.

Mixed record types:

H20240115Company Inc
D001Alice     1234.56
D002Bob       9876.00
T00212345.56

Header (H), detail (D), and trailer (T) records have different structures and lengths.

How the Converter Handles Short Lines

When a line is shorter than the total expected width:

  • Fields that start within the line but extend beyond it produce a partial value (whatever characters are available)
  • Fields that start entirely beyond the line length produce an empty string
  • A warning is shown: "Row X: line is Y chars but expected at least Z"

Strategies for Mixed-Length Data

  1. Pre-filter by record type: If different lines have different structures, filter them into separate groups and convert each with its own column definition
  2. Use the widest definition: Define columns to match the longest record type; shorter records will simply have empty trailing fields
  3. Pad short lines: Some preprocessing tools can pad lines with spaces to uniform length before conversion

Auto-Detection with Mixed Lengths

The auto-detect algorithm treats positions beyond a short line as spaces. If many lines are short, this can skew the boundary detection. For best results, ensure at least 70% of lines have full-length data.

Use Case

Processing log files, batch processing output, or legacy exports where trailing whitespace has been stripped, resulting in lines of varying length that still follow a fixed-width structure.

Try It — Fixed Width ↔ CSV Converter

Open full tool