I have a bucket on Amazon S3 with thousands of files that contain double spaces in their names.
How can I replace all the double spaces with one space?
like: folder1/folder2/file name.pdf
to folder1/folder2/file name.pdf
I have a bucket on Amazon S3 with thousands of files that contain double spaces in their names.
How can I replace all the double spaces with one space?
like: folder1/folder2/file name.pdf
to folder1/folder2/file name.pdf
Option 1: Use a spreadsheet
One 'cheat method' I sometimes use is to create a spreadsheet and then generate commands:
aws s3api list-objects --bucket bucket-name --query 'Contents[].[Key]' --output text | grep '\ \ ' >file_list.csv
aws s3 mv
command:="aws s3 mv 's3://bucket-name/"&A1&"' 's3://bucket-name/"&SUBSTITUTE(A1," "," ")&"'"
Option 2: Write a script
Or, you could write a script in your favourite language (eg Python) that will:
According to the idea from @john-rotenstein
I build bash command that makes it in one line
aws s3 ls --recursive s3://bucket-name | cut -c32- | grep "\/.* .*" | (IFS='' ; while read -r line ; do aws s3 mv s3://bucket-name/"$line" s3://bucket-name/$(echo "$line" | xargs) --recursive; done)