如何查找/修复具有混合行结尾的文件 (0x0d 0x0d 0x0a)
我知道我“可能”可以通过使用“flip -u”(cygwin Flip)来修复它们,它基本上删除了 0xd 之一,使文件带有 DOS 风格的行结尾(0x0d 0x0a)(当然,从技术上讲,这可能被认为是漏洞!)。
但另一方面,我想有选择地执行此操作,确保我要修复的确实是一个“非二进制”文件,并明确用 0x0d 0x0a 替换 0x0d 0x0d 0x0a 序列...不运行有缺陷的程序似乎可以做我想做的事(可能还有更多)。
请注意,grep -P '\x0d\x0d\x0a' 和 grep -P '\x0d\x0d' 找不到这些行。
尽管人们说 grep -P 'x0d\x0a' 可以正确查找行结尾,但我不得不猜测正在发生其他事情,因为它无法匹配具有混合行结尾的文件中的其他模式(0x0d 0x0d 0x0a )。
I know I can "probably" fix them by using "flip -u" (cygwin flip) which basically removes one of the 0xd's leaving the file with DOS style line endings (0x0d 0x0a) (of course, technically speaking this might be considered a bug!).
But the other side of it is that i'd like to do this selectively, ensuring that what I'm fixing really is a "non-binary" file and EXPLICITLY replacing the 0x0d 0x0d 0x0a sequence with 0x0d 0x0a... not running a buggy program that appears to do what I want (and possibly more).
Note that grep -P '\x0d\x0d\x0a' and grep -P '\x0d\x0d' do not find these lines.
Although people say that grep -P 'x0d\x0a' is properly finding line endings, I'd have to surmise that something else is going on since it can't match the other patterns in a file with mixed line endings (0x0d 0x0d 0x0a).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是识别包含混合行结尾的文件的简单方法:
-A
暗示-v
和-E
,其中包括行结尾和其他内容隐藏字符。例如,让我们创建一个测试文件。我将使用实际文本来表示与您将看到的行结尾相当接近的内容:现在让我们看看 cat 给了我们什么:
cat
确实向我们显示了 CR 和 LF(尽管 LF 没有) t 出现在同一行——这是理所当然的),所以现在我们可以找到它们:Here's an easy way to identify the files that contain mixed line endings:
The
-A
implies-v
and-E
which includes line endings and other hidden characters. For example, let's create a testfile. I'll use the actual text to represent fairly closely with the line endings you'll see:Now let's see what cat gives us:
cat
is indeed showing us the CRs and LFs (though the LFs don't show up on the same line -- and justifiably so), so now we can find them:您可以尝试 bbe (http://bbe-.sourceforge.net/):
它将替换该行以 Unix 行结尾结尾;或者:
它将用 DOS 行结尾替换它们。
You can try bbe (http://bbe-.sourceforge.net/):
which will replace the line ending by unix line endings; or:
which will replace them by DOS line endings.