【发布时间】:2016-04-05 15:59:02
【问题描述】:
我想从this file 中删除空行,以便歌曲的各节之间只有两个\n。第 7、8 和 20 行似乎有空格,但我猜它们不是常规空格,因为我无法通过使用 \s 的替换来删除它们。
文本复制如下(为清楚起见,空格标记为<-- HERE),但堆栈溢出编辑器似乎已将特殊空格更改为常规空格,因此您必须查看原始文件以进行复制我的问题。
9a I Believe in a Hill Called Mount Calvary
1 There are things, as we travel this earth's shifting sands,
That transcend all the reason
But the things that matter the most in this world,
They can never be held in our hand
<-- HERE
<-- HERE
Chorus
I believe in a hill called mount Calvary,
I believe whatever the cost!
And when time has surrendered and earth is no more
I'll still cling to that old rugged cross
2 I believe that the Christ who was slain on the cross,
Has the power to change lives today;
For He changed me completely a new life is mine
That is why by the cross I will stay
<-- HERE
3 I believe that this life, with its great mysteries,
Surely someday will come to an end;
But faith will conquer the darkness and death
And will lead me at last to my Friend
我尝试了perl -pe 's/\n{3,}/\n\n/g',但没有成功,因为第 7、8 和 20 行有一些空间。
无论我尝试什么,我都无法删除空间。我尝试了以下命令:
perl -p0e 's/\s{3,}/\n\n/g'perl -pe 's/^\s$//g'perl -pe 's/^ $//g'perl -pe 's/ $//g'
这些都不起作用。我想知道为什么会这样。会不会有一个non-space 字符充当空白?
我应该怎么做才能摆脱这个?
【问题讨论】: