0

我有一些草率的文字需要清理。不知何故,在段落中间插入了随机换行符。

This is a paragraph
and it got broken into two lines.

处理此问题的手动方法是

  1. 将光标放在第 2 行的开头
  2. 点击删除将该行带到第 1 行
  3. 点击空格将通过此操作混合在一起的两个单词分开

有没有办法通过查找和替换来实现这一点?^[a-z]我知道我可以通过检查“区分大小写”找到违规行,但这是我所能得到的。

我刚刚开始了解模式匹配的强大功能,并且我已经解决了所有其他清理问题,但这仍然让我感到困惑。

4

2 回答 2

0

使用awklinux

cat file
This is a paragraph
and it got broken into two lines.
This line is fine and should be printed.
Here is another
that has been broken.

awk 'NR>1 {printf "%s"(substr($0,1,1)~/^[[:lower:]]$/?FS:RS),a} {a=$0} END {print a}' file
This is a paragraph and it got broken into two lines.
This line is fine and should be printed.
Here is another that has been broken.
于 2014-06-10T06:41:20.123 回答
0

如果真的没有什么需要注意的,请搜索\n([a-z])find 的“匹配”“区分大小写”和“Grep”启用的情况下)并替换为\1. (搜索的表达式没有前导空格,而替换确实有一个。)

于 2014-11-04T23:19:52.150 回答