0

次のようなテキストファイルがたくさんあります。

His doctor attributed this to an allergy .

That hardly convinced him , as he had no history of allergies of any kind .
" Yet , that was to be the least of his problems .
I may have to take steroids for the rest of my life .
"
A topical steroid spray was later added to his repertoire of drugs and 
" he knew it was merely masking the underlying condition .
"

. "そして、一行になるように変更したいと思います。目的の出力は次のようになります。

His doctor attributed this to an allergy .

That hardly convinced him , as he had no history of allergies of any kind .
" Yet , that was to be the least of his problems .
I may have to take steroids for the rest of my life . "
A topical steroid spray was later added to his repertoire of drugs and 
" he knew it was merely masking the underlying condition . "

私はこれを試しましたが、機能しません:

sed -i 's/.\n"\n/. "\n/g'

誰かが上にシフトするための正しいsedコマンドで私を助けることができますか"

4

4 に答える 4

1
perl -00 -lpe 's/\n"$/"/mg'

目的の出力を生成します。

于 2012-04-25T15:14:14.317 に答える
1

これは私が理解したことです:

sed -n '1{h;d};/^"$/{g;s/$/ "/p;n;h;d};x;p;${g;p}' input.txt

出力

His doctor attributed this to an allergy .

That hardly convinced him , as he had no history of allergies of any kind .
" Yet , that was to be the least of his problems .
I may have to take steroids for the rest of my life . "
A topical steroid spray was later added to his repertoire of drugs and
" he knew it was merely masking the underlying condition . "
于 2012-04-25T14:53:43.030 に答える
1

わずかに異なるsedバリアント:

sed -n '1{h};1!{/"$/!H};/"$/{H;g;s/\.[ \n]*"$/\. "/;p;n;x}' input.txt
  • 1 { h }—最初の行をホールドバッファに入れます
  • 1! { /"$/ !H }—残りの行については、孤独でない場合はホールドバッファーに蓄積します"
  • /"$/ { H; g; s/\.[ \n]*"$/\. "/; p; n; x }- そうでなければ:

    1. H—ホールドバッファに追加します
    2. g—ホールドバッファをパターンスペースに移動します
    3. s/\.[ \n]*"$/\. "/—交換を行います
    4. p- 印刷する
    5. n—次の行を読む
    6. x—そしてそれをホールドバッファに保持します
于 2012-04-25T15:54:52.510 に答える
0

これはあなたのために働くかもしれません:

sed ':a;$!N;s/\.\n"/."/;P;D' /tmp/a
His doctor attributed this to an allergy .

That hardly convinced him , as he had no history of allergies of any kind ." Yet , that  was to be the least of his problems .
I may have to take steroids for the rest of my life ."
A topical steroid spray was later added to his repertoire of drugs and 
" he knew it was merely masking the underlying condition ."
于 2012-04-26T06:07:18.157 に答える