# Fixed Width to CSV Converter

Convert fixed-width records to CSV. Auto-detect aligned whitespace or enter exact widths/ranges, headers, delimiters, quoting, and line endings.

## Run it

- **CLI:** `gizza tool fixed-width-to-csv "name      age city
Ada        36 London
Bo          7 Oslo"`
- **Web:** https://gizza.ai/tools/fixed-width-to-csv/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/fixed-width-to-csv/tool.json

## Inputs

- `text` — Fixed-width text _(field)_
- `spec` — Column spec (optional) _(field)_
- `header` — Header row _(field)_
- `trim` — Trim whitespace from fields _(field)_
- `delimiter` — Output delimiter _(field)_
- `quote` — CSV quoting _(field)_
- `newline` — Line endings _(field)_
- `skip_lines` — Skip leading lines _(field)_
- `comment` — Comment prefix to ignore _(field)_
- `skip_blank` — Skip blank lines _(field)_
- `bom` — Add UTF-8 BOM for Excel _(field)_

## Output

- CSV output (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `text` — Fixed-width text
- `spec` — Column spec (optional)
- `header` — Header row
- `trim` — Trim whitespace from fields
- `delimiter` — Output delimiter
- `quote` — CSV quoting
- `newline` — Line endings
- `skip_lines` — Skip leading lines
- `comment` — Comment prefix to ignore
- `skip_blank` — Skip blank lines
- `bom` — Add UTF-8 BOM for Excel

Example: `https://gizza.ai/tools/fixed-width-to-csv/?text=name%20%20%20%20%20%20age%20city%0AAda%20%20%20%20%20%20%20%2036%20London%0ABo%20%20%20%20%20%20%20%20%20%207%20Oslo&spec=name%3A10%2Cage%3A4%2Ccity%3A%2A&header=first-row&trim=true&delimiter=comma&quote=minimal&newline=lf&skip_lines=0&comment=%23&skip_blank=true&bom=true`

---

## About this tool

Fixed-width text is common in mainframe exports, bank files, old reporting systems, COBOL-style extracts, and command output where columns are aligned by position instead of separated by commas. This converter turns those records into CSV without uploading anything.

Leave the column spec blank to auto-detect boundaries from whitespace that lines up on every row. For production imports, provide an explicit spec so the same layout is used every time: widths such as `10,4,*`, one-based ranges such as `1-10,11-14,15-30`, named widths such as `name:10,age:4,city:*`, or pipe-separated `position,length,name` entries such as `1,10,name|11,4,age|15,*,city`.

## Worked example

Input:

```text
name      age city
Ada        36 London
Bo          7 Oslo
```

With auto-detection and the default first-row header mode, the result is:

```csv
name,age,city
Ada,36,London
Bo,7,Oslo
```

For a repeatable import, use the spec `name:10,age:4,city:*` and set the header mode to “Use names from the column spec”. That reads characters 1-10 as `name`, 11-14 as `age`, and the rest of each line as `city`.

## Limits and edge cases

- Positions and widths are counted in Unicode characters, not UTF-8 bytes.
- The rightmost `*` column reads to the end of each line, so longer notes are not clipped.
- Short rows are padded with empty CSV fields.
- Auto-detection treats a character position as a separator only when every row has whitespace there, so explicit specs are safer for irregular files.
- A run converts up to 50,000 data lines and 512 columns.
- `quote=never` is intentionally lossy if a field contains the selected delimiter; use minimal quoting for normal CSV imports.

## FAQ

<details>
<summary>When should I use an explicit column spec instead of auto-detect?</summary>

Use an explicit spec when the file layout is known or must be repeatable. Auto-detect is convenient for quick report output, but a real fixed-width feed should usually be parsed with widths or ranges such as `10,4,*` or `1-10,11-14,15-30`.

</details>

<details>
<summary>Are column positions zero-based or one-based?</summary>

Specs use one-based positions because that is how most fixed-width layout documents describe columns. For example, `1-10` means the first through tenth characters. Width specs such as `10,4,*` start at character 1 and advance automatically.

</details>

<details>
<summary>Can I create TSV or semicolon-separated output?</summary>

Yes. Set the delimiter to `tab`, `semicolon`, `pipe`, `space`, `colon`, or any single character. The output still uses the same CSV quoting rules, so fields containing the delimiter are protected when `quote=minimal` or `quote=all` is selected.

</details>

<details>
<summary>Why did the first input line disappear from the data?</summary>

The default header mode treats the first line as column names. If your input has no header row, choose “Generate col1, col2, …” or “No header row”. If your spec has names such as `name:10,age:4`, choose “Use names from the column spec”.

</details>

## Related tools

- [Absolute value, sign, or negation for a whole column](https://gizza.ai/tools/absolute-value-transformer/): Paste a column of numbers and apply absolute value, sign extraction (-1/0/1), sign flipping, or force-negative to every value at once, with rounding and an audit table.
- [Adjacency Matrix Converter](https://gizza.ai/tools/adjacency-matrix-converter/): Convert a graph between edge list, adjacency matrix, and incidence matrix — directed or undirected, weighted or not. Free, private, runs in your browser.
- [Amazon Order Analyzer](https://gizza.ai/tools/amazon-order-analyzer/): Paste an Amazon order-history CSV export to summarize total spend by month, top items, and category breakdowns. Browser-only, private, with Markdown or JSON output.
- [ARFF Converter](https://gizza.ai/tools/arff-converter/): Convert Weka ARFF datasets to CSV and CSV tables back to ARFF locally — nominal attributes, numeric types, dates, sparse rows, missing values, and type rows.
- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
