如何使用gsutil命令列出gcs bucket中的所有文件(带有所有文件夹),以便在文件内容中匹配特定的字符串



我想列出gcs bucket中的文件,其中包含文件内容中特定字符串模式的多个文件夹。有没有使用阵风的快速解决方案?

#!/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!!"

这会奏效的。如果有人有更好的解决方案,请更新相同的

对于gsutil ls gs://path/to/folder/*.json中的i;执行gsutil cat$i|jq-r。;完成>file_mask_patterns.txt

最新更新