我正在一个程序中执行递归的 fgrep/grep -f 搜索,使用以下命令对一个被压缩的文件夹进行搜索:
我使用的命令:
grep -r -i -z -I -f /path/to/pattern/file /home/folder/TestZipFolder.zip
在模式文件中,我正在尝试搜索的字符串是“Dog”。
在压缩的文件夹中有许多包含字符串“Dog”的文本文件。
grep -f命令成功地找到了压缩文件夹内3个包含字符串“Dog”的文本文件,但它将输出打印在一行上,并且一些奇怪的字符出现在末尾,例如PK(如下所示)。当我尝试在程序中将输出打印到文件时,其他字符也会出现在末尾,例如^B^T^@
grep -f命令的输出:
TestZipFolder/test.txtThis is a file containing the string DogPKtest1.txtDog, is found again in this file.PKTestZipFolder/another.txtDog is written in this file.PK
当字符串“Dog”被找到时,我该如何使每个包含此字符串的文件打印在新行上,以便它们不像现在一样都聚集在一行上?
另外,输出中出现的“PK”和其他奇怪字符是从哪儿来的?如何防止它们出现?
期望输出结果
TestZipFolder/test.txt:This is a file containing the string Dog
TestZipFolder/test1.txt:Dog, is found again in this file
TestZipFolder/another.txt:Dog is written in this file
以下是类似的内容,用户可以看到字符串在文件中的位置(如果在非zip文件上运行grep命令,则会得到此格式的输出)。