llokely
llokely

Reputation: 93

Making csv from text using awk

I have a lot of txt files like this:

Title 1
Text 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?

Upvotes: 0

Views: 444

Answers (1)

asoundmove
asoundmove

Reputation: 1322

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.

Upvotes: 1

Related Questions