本文介绍了如何用MIXED行结尾找到/修复文件(0x0d 0x0d 0x0a)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过使用flip -u(cygwin flip)来修复它们,它基本上删除了其中一个0xd,使用DOS风格的行结尾(0x0d 0x0a)(当然,从技术上讲,这可能会导致被认为是一个错误!)。

但是另一方面,我想有选择地做这个,确保我正在修复的是一个非二进制文件,并显式替换0x0d 0x0d 0x0a序列0x0d 0x0a ...没有运行看起来做我想要的(也可能更多)的错误程序。



尽管人们说grep -P'x0d \x0a'正确地找到了行结尾,但是我不得不推测其他事情正在进行,因为它不能与具有混合行结尾的文件中的其他模式匹配(0x0d 0x0d 0x0a)。

解决方案

这是一个简单的方法来识别ify包含混合行结尾的文件:

  cat -A $ FILE | grep'\ ^ M\ ^ M\ $'

-A 隐含 -v 和 -E ,其中包含行结尾和其他隐藏字符。例如,我们来创建一个测试文件。我将使用实际的文本来代表您将看到的行结尾:
$ b $ pre $ code $ od -x test1。 txt
0000000 6464 2061 0d20 0a0d 6464 6161 2020 0d0d
0000020 0a0a 6164 2020 0a0d
0000030
$ / code>

现在我们来看看cat给了我们什么:

  $ cat -vE test1.txt 
dda ^ M ^ M $
ddaa ^ M ^ M $
$
da ^ M $



确实向我们展示了CR和LF(虽然LF并不显示在同一条线上 - 理由如此),所以现在我们可以找到它们:

pre $ find $ path $ yourPredicatesOfInterest -print |同时阅读fn;做
猫-A $ fn | grep'\ ^ M\ ^ M\ $'> / dev / null 2>& 1&& echo$ fn包含多个CR CR LFs
完成


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).

解决方案

Here's an easy way to identify the files that contain mixed line endings:

cat -A $FILE | grep '\^M\^M\$'

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:

$ od -x test1.txt
0000000 6464 2061 0d20 0a0d 6464 6161 2020 0d0d
0000020 0a0a 6164 2020 0a0d
0000030

Now let's see what cat gives us:

$ cat -vE test1.txt
dda  ^M^M$
ddaa  ^M^M$
$
da  ^M$

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:

find /path -yourPredicatesOfInterest -print | while read fn ; do
    cat -A $fn | grep '\^M\^M\$' > /dev/null 2>&1 && echo "$fn contains multiple CR CR LFs"
done

这篇关于如何用MIXED行结尾找到/修复文件(0x0d 0x0d 0x0a)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 17:45