Converting a text file to CSV is one of the most common data tasks there is — and also one of the most misunderstood. The actual file format difference between TXT and CSV is smaller than most people think. Both are plain text. Both store data as characters. The difference is structure: a CSV file uses commas to separate values into columns and line breaks to separate rows, following a defined pattern that every spreadsheet, database, and analytics tool understands natively.
A plain TXT file might have that same structure already — values separated by tabs, pipes, spaces, or commas — but saved with the wrong extension or without the standard delimiter that downstream tools expect. Converting it to CSV means reformatting the delimiter into standard comma separation and saving the result with a .csv extension so every tool opens it correctly.
This guide covers every method: a free online converter for quick single-file conversions, Microsoft Excel's built-in import wizard for structured workflows, and Python for batch or automated processing. It also covers the most common problems — encoding errors, misaligned columns, and delimiter confusion — and how to fix them.
What Is the Difference Between TXT and CSV?
A TXT file is a plain-text file with no defined structure. It can contain anything: prose, code, logs, data. A CSV file is also a plain-text file, but it follows a specific structure defined by RFC 4180 — each line is a data record, and each field within a record is separated by a comma. The .csv extension signals to applications that the file contains structured tabular data and should be opened as a spreadsheet rather than a document.
In practice, many TXT files already contain structured data — just with a different delimiter. Tab-separated files (TSV), pipe-separated files, space-delimited exports from legacy systems, and fixed-width report formats are all text files with structure. Converting them to CSV means either replacing the delimiter with a comma or reformatting the fixed-width layout into clean column-separated rows.
The reason this matters: Excel, Google Sheets, databases, CRMs, analytics tools, and data pipelines all expect CSV as their default import format. A .txt file opened in Excel may display everything in a single column, require manual splitting, or fail to import at all. The same data saved as .csv opens correctly, with columns aligned and data ready to use.
Method 1 — Convert TXT to CSV Online Free (Fastest)
The fastest method for occasional conversions is a browser-based tool. No software to install, no account required, no file size tricks.
How to convert TXT to CSV using Transfonic:
Upload your TXT file by dragging it onto the converter or clicking to browse
Select CSV as the output format
Click Convert and download your CSV file
Your file is processed in your browser and deleted immediately after conversion. No account, no watermark, no data retained.
When to use this method: Single files, quick conversions, situations where you do not have Excel or Python available, or when working on a device where installing software is not an option. Works on Windows, macOS, Linux, iOS, and Android.
Limitation: Online converters work best with consistently delimited text files — tab-separated, comma-separated, or pipe-separated. Fixed-width text files with no clear delimiter character may need manual adjustment after conversion.
Method 2 — Convert TXT to CSV Using Microsoft Excel
Excel's built-in Text Import Wizard handles the most common TXT-to-CSV conversion scenarios without any additional software. This method gives you full control over delimiter detection, column formatting, and encoding — making it the best choice for structured workflows where you need to review the data before saving. Full documentation is available on the Microsoft Support page for importing and exporting text files.
Steps to convert TXT to CSV in Excel:
Open Excel and create a new blank workbook
Go to Data → Get Data → From File → From Text/CSV
Browse to your TXT file and click Import
Excel opens a preview window and attempts to detect the delimiter automatically
If the detection is wrong, open the Delimiter dropdown and select the correct one — Tab, Comma, Semicolon, Space, or Custom
Review the column preview to confirm the data is splitting correctly
Click Load to bring the data into the spreadsheet
Go to File → Save As, choose a location, and select CSV (Comma delimited) (*.csv) from the Save as type dropdown
Click Save — Excel will warn that CSV format does not support multiple sheets; click OK to continue
If your TXT file uses tabs as separators: Select Tab as the delimiter in step 5. Tab-separated files are technically TSV format. If you have a TSV file, Transfonic's tsv to csv converter handles this directly without needing to open Excel.
If your TXT file came from a database export or an older system: It may use a pipe character (|) or a semicolon (;) as the delimiter. In step 5, select Custom and type the character your file uses.
Encoding note: If your data contains special characters — accented letters, non-Latin scripts, currency symbols — set the encoding to UTF-8 in the preview window before loading. Failing to do this is the most common cause of garbled characters in the output CSV.
Method 3 — Convert TXT to CSV Using Python
Python is the right tool when you have multiple files to convert, the process needs to run automatically on a schedule, or the TXT files are too large or too numerous to handle manually. Python's built-in csv module handles everything without any external libraries.
Basic TXT to CSV conversion in Python:
import csv
input_file = 'data.txt'
output_file = 'data.csv'
delimiter = '\t' # Change to '|' or ',' or ' ' to match your file
with open(input_file, 'r', encoding='utf-8') as txt_file:
lines = txt_file.readlines()
with open(output_file, 'w', newline='', encoding='utf-8') as csv_file:
writer = csv.writer(csv_file)
for line in lines:
row = line.strip().split(delimiter)
writer.writerow(row)
print(f"Converted {input_file} to {output_file}")
Change the delimiter variable to match whatever your TXT file uses to separate values: '\t' for tab, '|' for pipe, ',' for comma, ' ' for space.
Batch conversion — converting an entire folder of TXT files:
import csv
import os
input_folder = 'txt_files'
output_folder = 'csv_files'
delimiter = '\t'
os.makedirs(output_folder, exist_ok=True)
for filename in os.listdir(input_folder):
if filename.endswith('.txt'):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, filename.replace('.txt', '.csv'))
with open(input_path, 'r', encoding='utf-8') as txt_file:
lines = txt_file.readlines()
with open(output_path, 'w', newline='', encoding='utf-8') as csv_file:
writer = csv.writer(csv_file)
for line in lines:
row = line.strip().split(delimiter)
writer.writerow(row)
print(f"Converted: {filename}")
print("All files converted.")
Place all your TXT files in a folder named txt_files, run the script, and find the converted CSVs in csv_files. Adjust the delimiter to match your source files.
When to use Python: Any situation involving more than a handful of files, automated pipelines, scheduled exports from systems that produce TXT output, or integration with other data processing steps. Python's csv module also handles edge cases that online tools and Excel may miss — quoted fields containing commas, embedded newlines, and non-standard encodings.
Method 4 — Convert ODS to CSV
ODS (OpenDocument Spreadsheet) is the default format for LibreOffice Calc and other open-source spreadsheet applications. If your data is in an ODS file and you need it as CSV — for database import, data pipeline input, or sharing with a tool that does not support ODS — you can convert it directly without opening LibreOffice.
Transfonic's ods to csv converter handles ODS to CSV in the same three-step workflow: upload, select CSV output, download. No LibreOffice installation required. Files are deleted immediately after conversion.
Method 5 — Convert XLSX to CSV
If your data is in an Excel spreadsheet and you need it as CSV, the xlsx to csv converter is the fastest method. Upload your XLSX file, select CSV as the output, and download a clean comma-separated file ready to import into any tool. This is also covered in depth in the complete guide to how to convert xlsx to csv, which covers every method and every common problem including multi-sheet workbooks, encoding issues, and formula preservation.
Common Problems and How to Fix Them
Problem: Everything appears in a single column when I open the CSV in Excel
This happens when Excel does not detect the delimiter correctly, or when the CSV uses a semicolon instead of a comma (common in European locale settings). Fix: In Excel, go to Data → Text to Columns, select Delimited, choose Comma, and click Finish. This splits the single column into properly separated columns.
Problem: Special characters display as garbled symbols (Ãé, �)
This is an encoding mismatch. Your TXT file is encoded in UTF-8 but Excel is reading it as a different encoding (typically Windows-1252 or Latin-1). Fix in Excel: When using the Text Import Wizard, set File Origin to 65001: Unicode (UTF-8) before importing. Fix in Python: Always specify encoding='utf-8' in both the read and write operations.
Problem: My TXT file has inconsistent spacing instead of a clear delimiter
Fixed-width text files — common exports from mainframes, legacy accounting systems, and scientific instruments — use spaces to pad fields to a fixed character width rather than using a delimiter character. These require a different approach: you need to specify the exact character positions for each column. In Excel, use the Text Import Wizard and select Fixed Width instead of Delimited, then drag the column markers to the correct positions. In Python, use string slicing to extract each field by its character position.
Problem: My CSV has the wrong number of columns on some rows
This usually means some values in your TXT file contain the delimiter character (a comma inside a field that uses commas as separators). The correct fix is to ensure those fields are enclosed in double quotes in the output. Python's csv module handles this automatically — it will quote any field that contains a comma. Online tools and Excel may handle it inconsistently; if column counts are wrong after conversion, Python is the most reliable method.
Which Method Is Right for You?
Situation | Best Method |
One TXT file, quick result, no software | Online converter — csv conversion |
Need to review and adjust columns before saving | Excel Text Import Wizard |
Many files, batch processing, automated workflow | Python |
Tab-separated TSV file | |
ODS spreadsheet file | |
Excel XLSX spre Microsoft Support page for importing and exporting text files. adsheet |
