Guides / Text Conversion

How to Convert Text to CSV: Complete Guide

Multiple methods to convert plain text, lists, and tabular data into CSV format.

By Alex Kholodniak · ·

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:

  1. Paste your text data into the input box
  2. Select your input delimiter (tab, space, comma, etc.)
  3. Choose your output format options
  4. Click "Convert to CSV"
  5. 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:

  1. Open Excel and go to FileOpen
  2. Change file type to "All Files" and select your text file
  3. The Text Import Wizard will open
  4. Choose "Delimited" and click Next
  5. Select your delimiter (Tab, Comma, Space, etc.)
  6. Click Finish to import
  7. Save as CSV: FileSave AsCSV (Comma delimited)

For Lists (One Item Per Line):

  1. Copy your list
  2. Open Excel and paste into column A
  3. Each line becomes a row
  4. Save as CSV

Method 3: Using Google Sheets

Google Sheets provides an easy way to convert text to CSV:

  1. Open Google Sheets and create a new spreadsheet
  2. Paste your text data into cell A1
  3. If data is in one column, select it and go to DataSplit text to columns
  4. Choose your separator (detect automatically or select manually)
  5. Download as CSV: FileDownloadComma-separated values (.csv)

Method 4: Using Python

For automated or batch conversions, Python is an excellent choice:

python
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:

javascript
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:

bash
sed 's/\	/,/g' input.txt > output.csv

Space to CSV:

bash
sed 's/ /,/g' input.txt > output.csv

Warning: 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	34

Space-Separated

John Smith 28 NYC
Jane Doe 34 LA

Simple List

Apple
Banana
Orange
Grape

Pipe-Separated

John|john@example.com|28
Jane|jane@example.com|34

Best 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