[英]How to convert a text file to CSV using Bash
I've a text file with thousand of lines in it (each line has an email address) and I'd like to convert those to a CSV file using bash. 我有一个文本文件,其中包含数千行(每行都有一个电子邮件地址),我想使用bash将其转换为CSV文件。 The problem is I'm not well versed with Bash, so not sure how to go about doing it.
问题是我不太熟悉Bash,所以不确定如何去做。
Any suggestions? 有什么建议么?
EDIT: File example: 编辑:文件示例:
email@meail.com
email2@meail.com
email3@meail.com
email4@meail.com
This is ugly but it should work: 这很丑陋,但应该可以工作:
while read email; do echo '"'${email//\"/\"\"}'"'; done < inputfile.txt > output.csv
This escapes "
with ""
which is how CSVs are escaped in Excel land. 这种逃避
"
与""
这是CSV的是如何在Excel中的土地逃过一劫。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.