sed ':a;/0$/{N;s/
//;ba}'
In a loop (branch ba
to label :a
), if the current line ends in 0 (/0$/
) append next line (N
) and remove inner newline (s/
//
).
awk:
awk '{while(/0$/) { getline a; $0=$0 a; sub(/
/,_) }; print}'
Perl:
perl -pe '$_.=<>,s/
// while /0$/'
bash:
while read line; do
if [ ${line: -1:1} != "0" ] ; then
echo $line
else echo -n $line
fi
done
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…