我有一堆文本文件,如下所示:
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命令来移动"
吗?
答案 0 :(得分: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 . "
答案 1 :(得分:1)
perl -00 -lpe 's/\n"$/"/mg'
产生所需的输出。
答案 2 :(得分: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 }
- 否则:
H
- 添加到保留缓冲区g
- 将保留缓冲区移动到模式空间s/\.[ \n]*"$/\. "/
- 替换p
- 打印出来n
- 阅读下一行x
- 并将其保留在保留缓冲区中答案 3 :(得分: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 ."