Reputation: 131
I want to list the files in gcs bucket with multiple folders for a specific pattern of string within the file content. Is there any quick solution using gustil ?
Upvotes: 0
Views: 1510
Reputation: 1
for i in gsutil ls gs://path/to/folder/*.json
; do gsutil cat $i | jq -r .; done > file_mask_patterns.txt
Upvotes: 0
Reputation: 131
#!/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!!"
This will work. If someone have any better solution please update the same
Upvotes: 1