替换包含CRLF字符串? [英] Replace string that contains CRLF?

查看:1517
本文介绍了替换包含CRLF字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新格式化文件,我想执行以下步骤:

I'm reformatting a file, and I want to perform the following steps:


  1. 替换双CRLF的一个临时的字符序列( $ CRLF $ 或东西)

  2. 删除所有CRLF在整个文件

  3. 回去更换双CRLF的。

所以像这样输入:

This is a paragraph
of text that has
been manually fitted
into a certain colum
width.

This is another
paragraph of text
that is the same.

将成为

This is a paragraph of text that has been manually fitted into a certain colum width.

This is another paragraph of text that is the same.

看来这应该通过一些简单的 SED 程序管道输入的可能,但我不知道如何引用 CRLF SED (在使用 SED的/< CRLF>< CRLF> / $ CRLF $ /' )。或者,也许有这样做的更好的办法?

It seems this should be possible by piping the input through a few simple sed programs, but I'm not sure how to refer to CRLF in sed (to use in sed 's/<CRLF><CRLF>/$CRLF$/'). Or maybe there's a better way of doing this?

推荐答案

您可以使用SED装饰用{CRLF}月底所有行:

You can use sed to decorate all rows with a {CRLF} at end:

sed 's/$/<CRLF>/'

然后删除所有\\ r \\ n与TR

then remove all \r\n with tr

| tr -d "\r\n"

然后更换双CRLF与\\ n

and then replace double CRLF's with \n

| sed 's/<CRLF><CRLF>/\n/g'

和去除剩余的CRLF的。

and remove leftover CRLF's.

有是一个单行的sed这做这一切在一个周期内,但我似乎现在不能找到它。

There was an one-liner sed which did all this in a single cycle, but I can't seem to find it now.

这篇关于替换包含CRLF字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆