a**n 发帖数: 313 | 1 用sed 如何把多个空行并成一行.
==============================
testtest
testtest
=============================
变成:
==============================
testtest
testtest
=============================
thanks |
c**o 发帖数: 166 | 2 I did that in perl and failed doing that in sh. :)
【在 a**n 的大作中提到】 : 用sed 如何把多个空行并成一行. : ============================== : testtest : testtest : ============================= : 变成: : ============================== : testtest : testtest : =============================
|
c****j 发帖数: 258 | 3 sed -n '
#print first empty line
/^$/ p
#find next empty line, remove it
/^$/ {
N
s/.//
b Empty
}
#print non-empty lines
p
'
I don't like sed, but it can do something quite simply. |
q*z 发帖数: 13362 | 4 sed '/^$/d;G' input
【在 a**n 的大作中提到】 : 用sed 如何把多个空行并成一行. : ============================== : testtest : testtest : ============================= : 变成: : ============================== : testtest : testtest : =============================
|
c****j 发帖数: 258 | 5 You append an empty line to each non-empties.
【在 q*z 的大作中提到】 : sed '/^$/d;G' input
|
a**n 发帖数: 313 | 6 Thanks, it works.
【在 c****j 的大作中提到】 : sed -n ' : #print first empty line : /^$/ p : #find next empty line, remove it : /^$/ { : N : s/.// : b Empty : } : #print non-empty lines
|
q*z 发帖数: 13362 | 7 as his example showing
【在 c****j 的大作中提到】 : You append an empty line to each non-empties.
|
c**t 发帖数: 2744 | 8 UltraEdit can do this easily
【在 a**n 的大作中提到】 : 用sed 如何把多个空行并成一行. : ============================== : testtest : testtest : ============================= : 变成: : ============================== : testtest : testtest : =============================
|