这是个很有意思的问题:Linux下将文本中的`\r\n`转换成换行的效果

环境

  • ubuntu 14.04 64bit

  • vim

  • 包含大量\r\n的文本

问题描述

text1:

......
ssh_connect: needpriv 0   \r\n   debug1: Connecting to 192.168.10.130 [192.168.10.130]
port 22.   \r\n   debug2: fd 3 setting O_NONBLOCK   \r\n  debug1: fd 3 clearing 
O_NONBLOCK   \r\n   debug1: Connection established.   \r\   ndebug3: timeout: 10000 ms 
remain after connect\r\ndebug1: permanently_set_uid: 0/0\r\ndebug1: identity file 
......

说明:上面摘自错误输出,阅读起来很不友好。因为包含大量的\r\n(我用空格标记了),我把他们复制粘帖到vimatomgedit上\r\n都不会转换为换行效果。现在我想让\r\n转换成换行效果,如下:

ssh_connect: needpriv 0
debug1: Connecting to 192.168.10.130 [192.168.10.130]port 22.
debug2: fd 3 setting O_NONBLOCK
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug3: timeout: 10000 ms 
remain after connect
debug1: permanently_set_uid: 0/0
debug1: identity file 

请问大家有什么好的办法?

阅读 6.3k
1 个回答

使用 vim 的话::%s+\\r\\n+^M+g,其中^M使用Ctrl+vEnter输入。

推荐问题