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.
In Excel: Text-to-Columns
- Paste the text into column A.
- Select column A, then Data → Text to Columns.
- Pick Delimited, click Next, check the delimiter (Tab, Semicolon, Pipe, or Other).
- 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.