开发者

Making csv from text using awk

开发者 https://www.devze.com 2023-01-28 02:54 出处:网络
I have a lot of txt files like this: Title 1 Text 开发者_JS百科1 And I would like to make one csv file from all of them that it will look like this:

I have a lot of txt files like this:

Title 1
Text 开发者_JS百科1

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 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

or

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消