TextToolboxTextToolbox
Productivity5 min read

How to Extract and Reorder CSV Columns Without Losing Field Data

Follow tested CSV extraction and column-swap examples. Preserve quotes, spaces and identifiers, choose the right output and avoid unsafe line-based cleanup.

Saurabh Kumar

Written by Saurabh Kumar

Founder & maintainer of TextToolbox

Published:
Last edited:

To extract or reorder CSV columns, use a parser that understands quoted fields. A physical line is not always a complete record. Keep your original export, test a small sample and check the target import rules before changing the full dataset.

Reviewed October 10, 2026 against the current Extract Column and Swap Columns tools. The examples below are synthetic fixtures, not customer data.

Record tool or line tool?

CSV can contain a comma or a line break inside a double-quoted field. Embedded double quotes are escaped by doubling them. RFC 4180 describes common CSV quoting. Treating each physical line as a record can split a quoted value into unrelated pieces.

  • Extract one CSV field: use Extract Column in Quoted mode, and check the delimiter, column number, header and output format first.
  • Exchange two CSV fields: use Swap Columns in Quoted mode, and check that the selected fields exist in every record.
  • Split a literal multi-character separator: use either column tool in Literal mode; quotes then have no special meaning.
  • Sort or deduplicate full CSV records: use a CSV-aware spreadsheet or data application, and check the sort key, header and quoted multiline values.
  • Clean a plain one-value-per-line list: use a line tool after checking its options; the values must not contain embedded line breaks.

Line sorting or line deduplication is not automatically safe for a complete CSV export. Trimming can also change meaningful spaces. Decide which values or records count as duplicates before removing anything.

Extract a column and keep identifiers as text

Paste this fixture into Extract Column:

Name,ID,Note
"Doe, Jr.",00123,"said ""hello"""
Asha,9007199254740993,नमस्ते

Choose Quoted CSV-style fields, comma delimiter, column 2 and Plain text values. Enable Skip first record (header). Output:

00123
9007199254740993

The comma inside the name does not change the selected column. Both identifiers remain text: the leading zeros and the integer beyond JavaScript's safe-number range are preserved. The tool does not convert values to numbers or trim whitespace.

Without Skip first record, ID is the first output value. Header detection is explicit; the tool does not guess whether your first record is a header.

Reorder fields without breaking the quoted name

Paste the same fixture into Swap Columns. Choose Quoted mode, comma, Col A 1 and Col B 2. Output:

ID,Name,Note
00123,"Doe, Jr.","said ""hello"""
9007199254740993,Asha,नमस्ते

The header moves with its column. Other fields keep their raw quoting and spaces, and record endings are preserved. Applying the same swap to this output restores the original text. A same-column swap changes nothing, but still checks that the selected column exists.

Other permutations can be ambiguous. For example, moving part of an overlapping Literal separator can change where the next parse finds a field. Moving a value beginning with U+FEFF to the start can also turn payload text into an initial marker. Swap Columns blocks those candidates rather than silently escaping data. Choose a non-overlapping separator or prepare properly quoted fields in Quoted mode, then inspect the accepted result. This check concerns the received string; it does not verify original-file bytes or a spreadsheet import.

Choose extraction output carefully

Plain text extraction joins decoded values with LF. That is convenient for a simple list, but a value containing its own line break makes list boundaries ambiguous.

For example, consider two records:

1,"first line
second line"
2,plain
Three physical lines form two CSV recordsPhysical lines 1 and 2 belong to record 1: its second field contains first line, a line feed, then second line. The closing quote is on physical line 2. Physical line 3 contains record 2, with the fields 2 and plain.Physical lineLogical record1,"first linesecond line"2,plain123Record 1Record 2The quoted line break stays inside field 2.
Two logical records occupy three physical lines. In record 1, the LF between first line and second line belongs to the quoted second field. It does not start another record. This diagram explains the selectable source above; it is not a spreadsheet import.

Extract column 2 with One-column CSV. The first value remains one quoted field:

"first line
second line"
"plain"

The tool quotes every extracted CSV value, including empty values, and separates records with CRLF. Download saves this format as extracted-column.csv. Plain text download uses extracted-column.txt; Swap Columns downloads swapped-columns.txt. Copy uses exactly the displayed output.

Errors, and checking the result before you import

Message or symptomMeaningNext step
Selected column is missing in a recordThat record has too few fieldsInspect the reported record; correct the source or column choice
Unclosed quoted fieldA starting double quote has no matching endRepair quoting rather than deleting line breaks
Text after a closing quoteQuoted mode expects a delimiter or record ending nextRemove unintended outer text or use the intended source format
Empty or fractional column numberPositions must be positive whole numbersEnter a valid 1-based position
Backslash-t does not split TSVThose are two typed characters, not a tabUse the Tab preset
Swap would change field boundariesThe new order would parse into different fieldsUse a non-overlapping delimiter or correctly quoted source
Field-leading U+FEFF would become a markerA payload character would be reinterpreted at the startQuote that value in Quoted mode or keep another column order
Incomplete Unicode characterSource or delimiter contains a broken surrogate sequenceRepair the input rather than exporting replacement characters
Copy failedClipboard access did not succeedSelect the output and copy manually

The tools block the complete result on an error instead of exporting a mixture of changed and unchanged records. Blank records are retained. A blank record can therefore cause a missing-column error; delete it only if it is actually unintended.

These tools preserve field text and support quoted parsing with Unicode, CRLF, LF and lone CR endings. Literal mode accepts exact multi-character separators. They do not infer data types, run spreadsheet formulas, validate an import schema or make formula-like values inert.

A spreadsheet import may interpret text according to its own settings. Check how the target handles identifiers, dates, spaces and formula-like cells. Inspect a test import before uploading the full result. Keep the original file and avoid applying global trim, sort or deduplication just because the text looks untidy.

The current limits are 1,000,000 UTF-16 code units and 20,000 records. Use a suitable file-based data application for larger exports.