Skip to content

Instantly share code, notes, and snippets.

@powerswitch
Created October 24, 2012 15:29
Show Gist options
  • Save powerswitch/3946752 to your computer and use it in GitHub Desktop.
Save powerswitch/3946752 to your computer and use it in GitHub Desktop.
Extracts all *.zip files in the directory even with wide-chars in it
#!/bin/bash
mkdir "zip"
for f in *.zip
do
if unzip -q -u -d "${f%.zip}" "$f" ; then
mv "$f" "zip/$f"
else
a=true
unzip -Z -1 "$f" | egrep -v "^([-_\.:a-zA-Z0-9\t/, ])*\$" | while read var ; do
fn=$(echo "$var" | LANG=C sed "s#[^-_\.:a-zA-Z0-9\t]#_#g")
fn="${f%.zip}/$fn"
unzip -p "$f" "$(echo "$var" | LANG=C sed "s#[^-_\.:a-zA-Z0-9\t/, ]#*#g")" > $fn || a=false
done
$a && mv "$f" "zip/$f"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment