本文介绍了sed合并由空行分隔的N个文本行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了一下,但没有找到针对这种特定情况的解决方案.给定一个管道,它输出一组任意数量的非空行分隔的单个空行,是否有一个 sed one-liner(或 awk one-liner 或 perl one-liner)将非空行组组合成单行,同时保留空行?例如输入
I searched a bit, but didn't find a solution for this specific situation. Given a pipe that outputs groups of an arbitrary number of non-blank lines separated single blank lines, is there a sed one-liner (or awk one-liner or perl one-liner) that will combine the groups of non-blank lines into single lines, while preserving the blank lines? For example, the input
one
two
three
four
five
six
seven
eight
应该输出为
one two
three four five
six
seven eight
提前感谢所有回复的人.
Thanks in advance to all who respond.
推荐答案
Perl one-liner
Perl one-liner
perl -00 -lpe 'tr/\n/ /'
哪里
-00
读取以空行分隔的段落中的输入-l
自动处理换行符-p
处理后自动打印每条记录tr/\n//'
将所有换行符更改为空格
-00
reads the input in blank-line-separated paragraphs-l
automatically handles end-of-line newlines-p
automatically prints each record after processingtr/\n/ /'
changes all newlines to spaces
这篇关于sed合并由空行分隔的N个文本行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!