Unix 如何使用gsutil命令列出gcs bucket(带所有文件夹)中与文件内容中特定字符串匹配的所有文件
我想列出gcs bucket中的文件,其中包含文件内容中特定字符串模式的多个文件夹。使用gustil有什么快速解决方案吗?Unix 如何使用gsutil命令列出gcs bucket(带所有文件夹)中与文件内容中特定字符串匹配的所有文件,unix,gsutil,Unix,Gsutil,我想列出gcs bucket中的文件,其中包含文件内容中特定字符串模式的多个文件夹。使用gustil有什么快速解决方案吗?#/bin/bash #!/bin/bash read -p "Enter gcs path : " gcs_path read -p "Enter pattern : " pattern path=${gcs_path}** #pattern=$2 echo "loading the list of files.."
#/bin/bash
#!/bin/bash
read -p "Enter gcs path : " gcs_path
read -p "Enter pattern : " pattern
path=${gcs_path}**
#pattern=$2
echo "loading the list of files.."
gsutil ls -h $path > gcs_list.txt
echo "Looking for the pattern from the list...."
while read -r line ; do
##echo "Reading line : $line"
if gsutil cat $line | grep -q "$pattern" ; then
#true
echo " Match found for $line"
fi
done < gcs_list.txt
echo "Pattern search done!!"
阅读-p“输入地面军事系统路径:”地面军事系统路径
阅读-p“输入模式:”模式
路径=${gcs_path}**
#图案=$2
echo“正在加载文件列表…”
gsutil ls-h$path>gcs_list.txt
echo“从列表中查找模式…”
而read-r行;做
##回音“阅读行:$line”
如果gsutil cat$line | grep-q“$pattern”;然后
#真的
echo“为$line找到匹配项”
fi
完成
这会奏效的。如果有人有更好的解决方案,请更新相同的解决方案