Well, if your cat
implementation supports
-s, --squeeze-blank
suppress repeated empty output lines
then it is as simple as
$ cat -s a
1
2
3
4
5
Also, both -s
and -n
for numbering lines is likely to be available with less
command as well.
remark: lines containing only blanks will not be suppressed.
If your cat
does not support -s
then you could use:
awk 'NF||p; {p=NF}'
or if you want to guarantee a blank line after every record, including at the end of the output even if none was present in the input, then:
awk -v RS= -v ORS='
' '1'
If your input contains lines of all white space and you want them to be treated just like lines of non white space (like cat -s
does, see the comments below) then:
awk '/./||p; {p=/./}'
and to guarantee a blank line at the end of the output:
awk '/./||p; {p=/./} END{if (p) print ""}'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…