別の行の単語を1行にまとめる

別の行の単語を1行にまとめる

互いに下にある単語のリストを含むファイルがあります。ここで言葉は一つの文に属し、次の文に属する単語も互いに下にある。以下の表現#2に示すように、文に関連する単語ブロックの後にスペースが続きます。

期待される出力: (#1を意味する):

These are the words for sentence 1
These are the words for sentence 2

期待される入力:(#2の場合):

These
are
the
words
for
sentence 1

these
are
the
words
for
sentence 2

追いかけようとするこの問題しかし、文ごとに異なる単語を使用すると動作しませんが、Linuxで表現番号2を表現番号1にどのように変更できますか?

ベストアンサー1

$ awk -v RS= '{$1=$1}1' file
These are the words for sentence 1
these are the words for sentence 2

おすすめ記事