Reputation: 13
I have many big csv files under many folders and the file and folder have spaces in their names.
I now have the code below but it doesn't work when the file/folder has spaces in the name:
csv=$(find . -name "*.csv")
for f in $csv; do
echo "Compressing $f"
(cd $(dirname $f) && zip -j $(basename $f.zip) $(basename $f))
done
Upvotes: 1
Views: 155
Reputation: 16076
Have find
execute zip itself, since it still knows about all the spaces:
find -name '*.csv' -exec zip -j {}.zip {} \;
A direct port of what you wrote would use -execdir
in place of -exec
, but it appears not to be necessary.
Upvotes: 1