2010-12-04 7 views
0

J'ai beaucoup de fichiers txt comme ceci:Making csv du texte à l'aide awk

Title 1 
Text 1 

Et je voudrais faire un fichier csv de tous qu'il ressemblera à ceci:

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

Comment pourrais-je le faire en utilisant awk?

+1

double possible de [Faire csv à partir de fichiers txt] (http://stackoverflow.com/questions/4313247/making-csv-from-txt-files). S'il vous plaît modifier votre question initiale pour le clarifier. –

Répondre

1

Sans connaître plus en détail, les réponses suivantes ressemblent à de bonnes options:

awk '{printf "%s,", $0; getline; print}' 
# every second line gets merged with the previous line 

ou

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. 
Questions connexes