Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 如何';切割';空值?_File_Unix_Null_Cut_Nul - Fatal编程技术网

File 如何';切割';空值?

File 如何';切割';空值?,file,unix,null,cut,nul,File,Unix,Null,Cut,Nul,Unix“file”命令有一个-0选项,用于在文件名后输出空字符。这应该适合与“cut”一起使用 从手册文件: -0, --print0 Output a null character ‘\0’ after the end of the filename. Nice to cut(1) the output. This does not affect the separator which is still printed. (注意,在我的

Unix“file”命令有一个-0选项,用于在文件名后输出空字符。这应该适合与“cut”一起使用

手册文件

-0, --print0
         Output a null character ‘\0’ after the end of the filename. Nice
         to cut(1) the output. This does not affect the separator which is
         still printed.
(注意,在我的Linux上,没有打印“-F”分隔符,这对我来说更有意义。)

如何使用“剪切”从“文件”的输出中提取文件名

这就是我想做的:

find . "*" -type f | file -n0iNf - | cut -d<null> -f1
find。“*”-键入f | file-n0iNf-| cut-d-f1
其中
是NUL字符

这就是我想做的,我想做的是从一个目录树中获取所有文件名,这个目录树有一个特定的MIME类型。我使用grep(未显示)

我希望处理所有合法文件名,而不是在文件名中使用冒号,例如,在文件名中使用冒号。因此,NUL将是优秀的


我想非切割解决方案也不错,但我讨厌放弃一个简单的想法。

只需指定一个空分隔符:

cut -d '' -f1

(注意:
-d
'
之间的空格很重要,因此
-d
和空字符串作为单独的参数传递;如果您编写
-d'
,那么它将作为
-d
传递,然后
剪切
将认为您正在尝试使用
-f1
作为分隔符,我将使用它。)t会抱怨,错误信息是“分隔符必须是单个字符”。

这可能是我唯一没有尝试的事情!谢谢!@Sukima:它对我和OP都有效,所以说“这根本不起作用”显然是不正确的。OP指定他使用的是Linux(可能有特定于Linux的背景,
man file
说他可以使用
cut
分割空字符)。由于您的情况不同,您可能需要打开一个新问题。
cut:OSX上的分隔符不正确。@danielaolando:Yup。请阅读您的评论。谢谢。不幸的是,这不适用于busybox版本的cut。