从txt文件制作csv
我有很多这样的 txt 文件:
Title 1
Text 1(more then 1 line)
我想从所有这些文件中制作一个 csv 文件,它看起来像这样:
Title 1,Text 1
Title 2,Text 2
Title 3,Text 3
etc
我该怎么做?我认为 awk 很有用,但不知道如何实现它。
I have a lot of txt files like this:
Title 1
Text 1(more then 1 line)
And I would like to make one csv file from all of them that it will look like this:
Title 1,Text 1
Title 2,Text 2
Title 3,Text 3
etc
How could I do it? I think that awk is good for it but don't know how to realize it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以建议:
要处理大量文件,每个输出文件最多 40 个(未经测试,但接近):
May I suggest:
To handle large numbers of files, max 40 per output file (untested, but close):
这大约是您发布的内容,并进行了一些改进。
编辑:
如果您有一堆仅包含两行的文件,请尝试以下操作:
如果每个文件包含两行以上,那么它将把每对行放在同一行上,并用逗号。
This is approximately what you posted with some improvements.
Edit:
If you have a bunch of files that consist of only two lines, try this:
If the files contain more than two lines each then it will put each pair of lines on the same line separated by a comma.
给定 3 个包含以下数据的文件:
file1.txt
file2.txt
file3.txt
预期结果是:
这是使用程序 createcsv 完成的下面的 .awk 被调用为
createcsv.awk
Given 3 files containing the following data:
file1.txt
file2.txt
file3.txt
The expected results are:
This is accomplished using the program createcsv.awk below invoked as
createcsv.awk