Linux的GNU排序:如何使用NULL(\\ 0)作为分隔符 [英] linux GNU sort: how to use NULL (\0) as delimiter
问题描述
我要寻找一种方式来的结果进行排序找到
在bash脚本进行进一步的处理正确返回一个数字的目录。因为文件名不能包含NULL(\\ 0)字符我认为这将使得对结果有很大的分隔符被输送到排序
。
i am looking for a way to sort the results of find
returning a number of directories correctly for further processing in a bash script. since filenames can't contain the NULL (\0) character i thought this would make a great delimiter for the results being piped to sort
.
所以这就是我所期待所描述的工作:
so this is what i would expect to work as described:
find ./ -maxdepth 1 -type d -iname 'xyz?' -print0 | sort -t $'\0'
但遗憾的是我得到了compaint 排序:空标签
四处寻找一个解释跨越<少时href=\"http://stackoverflow.com/questions/5797369/unix-sort-utility-use-hexadecimal-value-as-delimiter\">question导致类似的结果,即的描述为工作正常运(见4月26日的卢卡斯注释)。在我的情况(使用GNU排序v 7.4),这是似乎有所不同。
looking around for a explanation a came across a question leading to a similar result that the op described as working fine (see lucas comment of apr 26th). in my case (using GNU sort v 7.4) this is seems different.
我也通过管道到 OD -c
检查发现的输出,但是这只能表明所产生的文件夹由NULL分隔预期。
i also checked the output of find by piping into od -c
but this only shows that the resulting folders are separated by NULL as expected.
在这里任何人都碰到过类似的情况,可能找到了解决或解释为何\\ 0似乎是那种不可能的分隔符?
has anybody here come across a similar scenario and possibly found a solution or explanation why \0 seem to be an impossible delimiter for sort?
期待你的回答......
looking forward to you answers...
编辑:注意,FIND命令被用作一个例子在这里,一个更简单的方法来测试/演示,这可能是呼应的g \\ 0 U \\ 0B \\ 0K |排序-t $'\\ 0'
edit: note that the find-command is used as an example here, a simpler way to test/illustrate this could be echo "g\0u\0b\0k" | sort -t $'\0'
推荐答案
-t
是的字段的分隔符。如果你想使用 \\ 0
为行的分隔符,那么你需要使用 -z
。
-t
is the field separator. If you want to use \0
as the line separator then you need to use -z
.
这篇关于Linux的GNU排序:如何使用NULL(\\ 0)作为分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!