【发布时间】:2012-04-25 14:51:42
【问题描述】:
我有一堆看起来像这样的文本文件:
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单独在行上工作。 -
那么有没有其他非sed的方式来解决呢??
-
这将强制出现带有 " 的第二行。您不能明确查找换行符。现在,下一步是去掉引号并加入这两行。尝试替换时或搜索 \n,改用 $。这是连续处理两行的方法。我看到了 perl 解决方案,这可能是一个好方法。sed -e '/\.$/ { N /"/p }' test.txt N和/"/p}'之间有一个换行符。