How to Create a CSV File From Plain Text

If your data is already in a text file — maybe pipe-delimited, tab-delimited, or just one record per line — converting it to CSV takes one of three approaches: Excel's Text-to-Columns wizard, a quick text-editor find-and-replace, or a one-liner in a scripting language.

Generate matching mock data right now

No sign-up, runs 100% in your browser, exports straight to CSV.

In Excel: Text-to-Columns

  1. Paste the text into column A.
  1. Select column A, then Data → Text to Columns.
  1. Pick Delimited, click Next, check the delimiter (Tab, Semicolon, Pipe, or Other).
  1. Click Finish, then File → Save As → CSV UTF-8.

In a text editor: find and replace

If the input is tab-delimited, just rename .txt to .csv and most importers accept it as TSV. If it's pipe-delimited, do Find: `|`, Replace: `,` — but quote any fields that contain commas first.

One-liner with awk

awk -F'|' '{ gsub(/,/, "", $0); $1=$1 } 1' OFS=',' input.txt > output.csv

Frequently asked questions

What if my text has irregular spacing?

Use a regex find-and-replace to normalize whitespace first, then convert.

Is renaming .txt to .csv enough?

Only if the file is already comma-separated. Otherwise convert the delimiter first.

Related guides

Start generating free mock CSVs

High-fidelity mock tables for tests, demos, or models. No sign-ups, completely local.