成績表のテキストファイルがたくさんあります。ある程度まとめられました。最後のクリーニングは次のとおりです。
*.txt ファイルにこの内容があります。
Gary: I said something.
Larry: I said something else.
Mr. John: I said this. And maybe this
and I also said this.
Laura: did i say anything.
私はこれが必要です。
Gary: I said something.
Larry: I said something else.
Mr. John: I said this. And maybe this and I also said this.
Laura: did i say anything.
行を移動したい。いいえ前の行にはコロン(:)が含まれています。最後に、各行に改行で終わる文字会話を含めたいと思います。
私はこれを見た質問しかし、どうすればいいのかわかりません。私はsed/awk/python/bash/perlツールなら何でも使うことができます。
ベストアンサー1
Sedを使用すると、パターンスペースに行を追加し、追加された部分(追加の改行からパターンの終わりまで)にコロン以外の文字のみが含まれていることを確認し、その後、最後の改行を空白に置き換えることができます。
sed -e :a -e '$!N; s/\n\([^:]*\)$/ \1/;ta' -e 'P;D' file.txt
Gary: I said something.
Larry: I said something else.
Mr. John: I said this. And maybe this and I also said this.
Laura: did i say anything.