Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.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
Bash 如何查找包含空字符串的文件_Bash - Fatal编程技术网

Bash 如何查找包含空字符串的文件

Bash 如何查找包含空字符串的文件,bash,Bash,我们的一个供应商有一个小车车间系统(长话短说)。虽然他们修复了终端的错误,但我需要隔离他们发送的文件:它们不是空的,而是一个长的空字符串。通常,一个好的文件在vi中会是这样的 <insert_list><test_event_insert endTime="2012-09-10T05:28:45" startTime="2012-09-10T05:27:41" operator="8176967"><process_step name="FVT" revi

我们的一个供应商有一个小车车间系统(长话短说)。虽然他们修复了终端的错误,但我需要隔离他们发送的文件:它们不是空的,而是一个长的空字符串。通常,一个好的文件在vi中会是这样的

    <insert_list><test_event_insert  endTime="2012-09-10T05:28:45" startTime="2012-09-10T05:27:41" operator="8176967"><process_step name="FVT" revision="NO DATA"></process_step><location1 name="CT" type="REGION"><location2 name="ONTREP1" type="TESTER"><location3 name="LineA" type="LINE"></location3></location2></location1><unit ...
"CT~DCA~FVT~8176967~ONTREP1~4~P~1100~DECA1MR0-01~XED1B1033A4675~20120910~052846.XML" [noeol][dos] 3L, 2170C
插入符号/at符号组合是VI对该字符串的解释,我猜,但它实际上是一个空字符串。使用
-z
似乎可以在单个文件上工作

X=CT~DCA~FVT~8176967~ONTREP1~2~P~1100~DECA1MR0-01~XED1B1045B6072~20120904~043209.XML
if [ ! -z $X ] 
then 
echo "$X empty"
else 
echo "$X not empty"
fi
    CT~DCA~FVT~8176967~ONTREP1~2~P~1100~DECA1MR0-01~XED1B1045B6072~20120904~043209.XML empty
但同样的代码告诉我,我的EMC海量文件管理器上的所有900个文件都是空的。但事实并非如此

export OUT=/path/to/device
declare -a myArray
for f in "$OUT"/*ONTREP1*; do myArray+=( "${f#$OUT/}" ); done
for i in "${myArray[@]}"; do  if [ ! -z $i ] ; then echo "$i empty"; else echo "$i not empty"; fi; done
注意:模式“ONTREP1”是将错误文件缩小到一个车间计算机名


我遗漏了什么?

您遗漏了
test-z string
测试字符串是否为空(与测试文件是否为空的
test-s file
相反)。此外,vim中的^@表示NUL字节——值为0的字节。看起来这些是二进制数据文件,或者可能已损坏,但肯定不是空的。vim中的空文件显示为最左边列中的所有波浪号(~):-)


尝试对好文件和坏文件运行
文件名
命令;由于NUL字节的缘故,后者可能会显示“data”。

如果grep'\x00'文件名为,请尝试
。不过,并不是所有的grep支持\x00。对文件-b${filename}=“data”的过滤处理了它。非常感谢。接受并投票通过。
export OUT=/path/to/device
declare -a myArray
for f in "$OUT"/*ONTREP1*; do myArray+=( "${f#$OUT/}" ); done
for i in "${myArray[@]}"; do  if [ ! -z $i ] ; then echo "$i empty"; else echo "$i not empty"; fi; done