How to Convert Text to CSV: Complete Guide
Multiple methods to convert plain text, lists, and tabular data into CSV format.
Converting text data to CSV format is a common task for data analysts, developers, and anyone who works with spreadsheets. This guide covers multiple methods, from the quickest online tools to programmatic solutions.
Method 1: Online Text to CSV Converter (Fastest)
The quickest way to convert text to CSV is using an online converter. Our Text to CSV Converter is free, works directly in your browser, and requires no signup.
How to use:
- Paste your text data into the input box
- Select your input delimiter (tab, space, comma, etc.)
- Choose your output format options
- Click "Convert to CSV"
- Download the file or copy to clipboard
Privacy benefit: All conversion happens in your browser. Your data is never uploaded to any server.
Method 2: Using Microsoft Excel
Excel can import text files and convert them to CSV format.
For Tab or Comma-Separated Text:
- Open Excel and go to File → Open
- Change file type to "All Files" and select your text file
- The Text Import Wizard will open
- Choose "Delimited" and click Next
- Select your delimiter (Tab, Comma, Space, etc.)
- Click Finish to import
- Save as CSV: File → Save As → CSV (Comma delimited)
For Lists (One Item Per Line):
- Copy your list
- Open Excel and paste into column A
- Each line becomes a row
- Save as CSV
Method 3: Using Google Sheets
Google Sheets provides an easy way to convert text to CSV:
- Open Google Sheets and create a new spreadsheet
- Paste your text data into cell A1
- If data is in one column, select it and go to Data → Split text to columns
- Choose your separator (detect automatically or select manually)
- Download as CSV: File → Download → Comma-separated values (.csv)
Method 4: Using Python
For automated or batch conversions, Python is an excellent choice:
import csv
# Read text file
with open('input.txt', 'r') as f:
lines = f.readlines()
# Write CSV file
with open('output.csv', 'w', newline='') as f:
writer = csv.writer(f)
for line in lines:
# Split by tab (change '\t' to your delimiter)
row = line.strip().split('\t')
writer.writerow(row)
print("Conversion complete!")The Python csv module handles proper escaping automatically, ensuring RFC 4180 compliance.
Method 5: Using JavaScript (Node.js)
For web developers or Node.js environments:
const fs = require('fs');
const text = fs.readFileSync('input.txt', 'utf8');
const lines = text.trim().split('\n');
const csv = lines.map(line => {
const fields = line.split('\t');
return fields.map(field => {
// Escape quotes and wrap in quotes if needed
if (field.includes(',') || field.includes('"') || field.includes('\n')) {
return '"' + field.replace(/"/g, '""') + '"';
}
return field;
}).join(',');
}).join('\n');
fs.writeFileSync('output.csv', csv);
console.log('Conversion complete!');Method 6: Command Line (Linux/Mac)
For quick conversions in the terminal:
Tab to CSV:
sed 's/\ /,/g' input.txt > output.csvSpace to CSV:
sed 's/ /,/g' input.txt > output.csvWarning: These simple commands don't handle quoting or escaping. For complex data, use a proper tool.
Common Input Formats
Tab-Separated (TSV)
Name Email Age
John john@example.com 28
Jane jane@example.com 34Space-Separated
John Smith 28 NYC
Jane Doe 34 LASimple List
Apple
Banana
Orange
GrapePipe-Separated
John|john@example.com|28
Jane|jane@example.com|34Best Practices
- Check your delimiter: Identify what separates your columns (tab, space, comma, pipe, etc.)
- Handle special characters: Ensure commas and quotes in your data are properly escaped
- Use UTF-8 encoding: Preserve international characters by using UTF-8
- Include headers: Add column names in the first row for clarity
- Validate output: Open the CSV in a spreadsheet to verify correct parsing
Quick Start
For most users, the fastest solution is our online converter. Just paste your text, click convert, and download.
Try Text to CSV Converter