[英]sed with newlines and "
我有一堆看起來像這樣的文本文件:
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命令,以將"
向上移動"
嗎?
這是我想出的:
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 . "
perl -00 -lpe 's/\n"$/"/mg'
產生所需的輸出。
sed
略有不同:
sed -n '1{h};1!{/"$/!H};/"$/{H;g;s/\.[ \n]*"$/\. "/;p;n;x}' input.txt
1 { h }
—將第一行放入保持緩沖區 1! { /"$/ !H }
1! { /"$/ !H }
-為線的其余部分,積聚成保持緩沖區,如果沒有寂寞"
/"$/ { H; g; s/\\.[ \\n]*"$/\\. "/; p; n; x }
/"$/ { H; g; s/\\.[ \\n]*"$/\\. "/; p; n; x }
-否則:
H
添加到保持緩沖區 g
—將保持緩沖區移至模式空間 s/\\.[ \\n]*"$/\\. "/
—進行替換 p
打印出來 n
—閱讀下一行 x
並將其保存在保持緩沖區中 這可能對您有用:
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 ."
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.