用awk从文本进行CSV [英] Making csv from text using awk
本文介绍了用awk从文本进行CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有很多的txt文件是这样的:
I have a lot of txt files like this:
Title 1
Text 1
和我想从所有的人都做一个csv文件,它会是这样的:
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
我
如何能做到这一点用awk?
How could I do it using awk?
推荐答案
不知道任何更多的细节,下面的答案看起来不错的选择:
Without knowing any more detail, the following answers look like good options:
awk '{printf "%s,", $0; getline; print}'
# every second line gets merged with the previous line
或
awk \
'
$0 ~ /^Title/ {printf "\n"}
{printf "%s,", $0}
'
# every line that starts with Title starts
# a newline and the rest is merged into one
# long line separated by commas.
这篇关于用awk从文本进行CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文