2010-12-04 3 views
0

を使用してテキストからCSV私はこのようなTXTファイルの多くを持って作る:はawkの

Title 1 
Text 1 

そして私は、それは次のようになりますことを、それらのすべてから1つのCSVファイルを作成したいと思います:

Title 1,Text 1 
Title 2,Text 2 
Title 3,Text 3 
etc 

awkを使ってどうすればいいですか?

+1

可能な複製(http://stackoverflow.com/questions/4313247/making-csv-from-txt-files)。オリジナルの質問を編集して明確にしてください。 –

答えて

1

任意の詳細を知らなくても、次の答えは良いオプションのように見える:[TXTファイルからCSVを作成]の

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.