Fixed Width to CSV Converter
A fixed width to CSV converter turns a mainframe extract, a bank statement or an instrument report into a spreadsheet. This one finds the column boundaries by looking for the whitespace that runs down the whole file, tells you what it found, and takes character positions typed by hand for the files where that signal is not there. Nothing is uploaded.
Want to profile, filter or join the result? Open the app
How the boundaries are found
A fixed-width file does not carry its layout. There is no delimiter to look for, so the boundaries have to be inferred from the shape of the text, and the signal is simpler than it sounds.
A character position counts as a gap when every line is blank at that position. In a real fixed-width report that produces a column of whitespace running the full height of the file at each field edge, which is exactly what a delimited file does not have. Two or more adjacent blank positions is a gap; one is not, because a single space appears inside plenty of ordinary values.
Take this:
SKU DESCRIPTION WAREHOUSE ON HAND
AC-00412 Aluminium bracket, 40mm Rotterdam 1420
BR-01730 Bronze bushing, 17mm bore Hamburg 3105
CL-00088 Cable clip, nylon, black Felixstowe 18400
The description column contains commas and spaces, so no delimiter sniffing would ever get this right. But the columns at positions 8 to 10, and again after "40mm", are blank on every single line, and that is the boundary. Four fields, cleanly.
What comes back has its padding trimmed:
SKU,DESCRIPTION,WAREHOUSE,ON HAND
AC-00412,"Aluminium bracket, 40mm",Rotterdam,1420
BR-01730,"Bronze bushing, 17mm bore",Hamburg,3105
The commas inside the descriptions are quoted properly, which is the other half of the job and the reason pasting a fixed-width file into a spreadsheet as comma-delimited does not work.
When detection fails, and what to do
There is one case the whitespace signal cannot see: a field that is completely full on every row, with no space before the next one begins. Then there is no blank column at that boundary and the two fields read as a single one.
It happens with tightly packed mainframe records where every byte is allocated, and with numeric fields padded with leading zeros rather than spaces. Both are common in banking and payroll extracts.
For those, type the boundaries in. They are the character positions where each field starts, counting from zero, comma separated:
0, 11, 42, 55, 70
Position zero is treated as a boundary whether you type it or not, because a spec that starts at 11 would silently discard the first field. The numbers are sorted, and spaces around the commas are fine.
Where do the right numbers come from? Ideally the record layout the file's producer gave you, which for a mainframe file is usually a COBOL copybook with PIC clauses and positions. Failing that, open the file in a monospaced editor with a column ruler and count.
And if the file came out of the CSV to fixed width converter on this site, the boundaries are appended to it as a comment block, in an offset table, a pandas read_fwf snippet or a COBOL layout. That is precisely why that option exists: it makes the round trip reliable rather than lucky.
Headers, short lines and what gets trimmed
The first line is treated as a header by default, since almost every report has one. Turn that off and it is kept as data, with columns named column_1 upward. A blank cell in the header row gets a placeholder name rather than leaving a column with no heading, and duplicate headings are suffixed apart so no column is lost when the rows become objects downstream.
Short lines are the other thing to know about. Trailing spaces get stripped somewhere in almost every transfer, so a row whose last field is empty arrives shorter than the others. Those are padded out with empty cells and the count is reported, which keeps the table rectangular and tells you it happened in case it means something other than a blank field.
Every value is trimmed of the padding around it, so a field written as Hamburg arrives as Hamburg. Leading spaces that were alignment padding on a right-aligned numeric field go the same way.
Blank lines are skipped rather than becoming empty rows. A report with a blank line between page breaks converts cleanly.
What is not attempted is type conversion. Everything comes out as text, so a zero-padded account number keeps its zeros and a code that looks like a date stays a code. If you want types, the app will profile the columns once the file is a table.
Questions
How are the column boundaries found?
By looking for character positions that are blank on every line. In a real fixed-width file there is a column of whitespace running the full height at each field edge, and that is a signal a delimited file does not give off. Two or more adjacent blank positions count as a gap; a single one does not, because a single space appears inside plenty of values.
When does the detection fail?
When a field is completely full on every row, with no space before the next one. Then there is no blank column at that boundary and the two fields read as one. That happens with tightly packed mainframe records and with numeric fields padded with zeros rather than spaces. For those, type the character positions in the boundaries box.
How do I write the manual boundaries?
As comma-separated character positions where each field starts, counting from zero: 0, 11, 42, 55. Position zero is always treated as a boundary whether you type it or not, since a spec that starts elsewhere would silently drop the first field. Spaces around the commas are fine and the numbers are sorted for you.
Where do I get the right positions?
From the record layout the file's producer should have given you, or by counting in a monospaced editor with a column ruler. If the file came out of the CSV to fixed width converter on this site, the boundaries are appended to it as a comment block, which is exactly why that option exists.
Is the first line treated as a header?
Yes by default, since most reports carry one. Turn it off and the first line is kept as data and the columns are named column_1 upward. A blank cell in the header row gets a placeholder name rather than an empty column heading.
What happens to lines that are shorter than the last column?
They are padded out with empty cells and the count is reported. Trailing spaces are often stripped somewhere in transit, so a row whose last field is blank arrives as a short line. Padding keeps the table rectangular, and the count tells you it happened in case it means something else.
Is my file uploaded?
No. Everything runs in your browser tab, with nothing sent to a server, nothing kept between visits and no row cap. Fixed-width files come out of banks, payroll systems and lab instruments, which are exactly the files that should not pass through anybody else's server.
Related
Convert your fixed width file to CSV
No sign-up, no upload, no row cap. Boundaries detected or typed in, padding trimmed, commas quoted properly.
Back to the converter