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.
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
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 symptom | Meaning | Next step |
|---|---|---|
| Selected column is missing in a record | That record has too few fields | Inspect the reported record; correct the source or column choice |
| Unclosed quoted field | A starting double quote has no matching end | Repair quoting rather than deleting line breaks |
| Text after a closing quote | Quoted mode expects a delimiter or record ending next | Remove unintended outer text or use the intended source format |
| Empty or fractional column number | Positions must be positive whole numbers | Enter a valid 1-based position |
| Backslash-t does not split TSV | Those are two typed characters, not a tab | Use the Tab preset |
| Swap would change field boundaries | The new order would parse into different fields | Use a non-overlapping delimiter or correctly quoted source |
| Field-leading U+FEFF would become a marker | A payload character would be reinterpreted at the start | Quote that value in Quoted mode or keep another column order |
| Incomplete Unicode character | Source or delimiter contains a broken surrogate sequence | Repair the input rather than exporting replacement characters |
| Copy failed | Clipboard access did not succeed | Select 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.
Recommended articles
Productivity
How to Remove Emojis from Text Without Losing Names
Choose a sequence-aware emoji filter, preserve multilingual names and text symbols, and compare tested whitespace settings before copying a reduced draft.
Productivity
How to Remove Duplicate Lines from a List (3 Free Methods)
Compare three duplicate-removal workflows with tested first-occurrence, case, edge-space, blank and Unicode examples. Keep meaningful record structure intact.