&引用;非法字节序列“;在bash中,我如何找到它?

&引用;非法字节序列“;在bash中,我如何找到它?,bash,vim,Bash,Vim,尝试在osx(bash)上对文本文件进行排序时,出现以下错误: 排序:字符串比较失败:字节序列非法 排序:设置LC_ALL='C'以解决问题。 排序:比较的字符串为“\363\272\331DR\371”和“201310”。 网络上充斥着按照错误建议设置LC_ALL的建议。但是,我想找到这个非法字节序列的位置 我正在解析来自许多第三方的数据,在将数据写入单个文件(最终上传到数据库)之前,我会进行各种规格化。这个数据中应该没有花哨的字符,这个错误告诉我在这个过程中的某个地方有损坏。然而,我找不到它

尝试在osx(bash)上对文本文件进行排序时,出现以下错误:

排序:字符串比较失败:字节序列非法 排序:设置LC_ALL='C'以解决问题。 排序:比较的字符串为“\363\272\331DR\371”和“201310”。 网络上充斥着按照错误建议设置LC_ALL的建议。但是,我想找到这个非法字节序列的位置

我正在解析来自许多第三方的数据,在将数据写入单个文件(最终上传到数据库)之前,我会进行各种规格化。这个数据中应该没有花哨的字符,这个错误告诉我在这个过程中的某个地方有损坏。然而,我找不到它

我试着将文件“分割”成越来越小的部分,这样我就可以直观地找到角色,但我做不到。我不能在vim或升华文本中找到它


你知道我如何找到这个腐败的地点吗?

这个对你有帮助吗

grep -n $(echo -e '\0363\0272\0331DR\0371') filename
<> P>自动地做事情,你可以考虑修改源代码

coreutils-8.23/lib/xmemcoll.c

static void
collate_error (int collation_errno,
               char const *s1, size_t s1len,
               char const *s2, size_t s2len)
{
  error (0, collation_errno, _("string comparison failed"));
  error (0, 0, _("Set LC_ALL='C' to work around the problem."));
  error (exit_failure, 0,
         _("The strings compared were %s and %s."),
         quotearg_n_style_mem (0, locale_quoting_style, s1, s1len),
         quotearg_n_style_mem (1, locale_quoting_style, s2, s2len));
}

至少通过这种方式,您可以轻松地编写一个垃圾箱文件,将所有这些行放入检查。

看起来有些地方使用了非ASCII字符。。也许您可以在使用UTF-8之前尝试将所有输入转换为UTF-8,并相应地设置您的环境?您是如何grep的
LC_ALL=C fgrep$'\363\272\331DR\371'您的输入
static void
collate_error (int collation_errno,
               char const *s1, size_t s1len,
               char const *s2, size_t s2len)
{
  error (0, collation_errno, _("string comparison failed"));
  error (0, 0, _("Set LC_ALL='C' to work around the problem."));
  error (exit_failure, 0,
         _("The strings compared were %s and %s."),
         quotearg_n_style_mem (0, locale_quoting_style, s1, s1len),
         quotearg_n_style_mem (1, locale_quoting_style, s2, s2len));
}