Skip to content

Instantly share code, notes, and snippets.

@notdodo
Created December 31, 2018 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notdodo/546311bc54390c4da32782cdda8f55eb to your computer and use it in GitHub Desktop.
Save notdodo/546311bc54390c4da32782cdda8f55eb to your computer and use it in GitHub Desktop.
Clean VBA: this script should remove unused variables in obfuscated VBAs (should work also for other files)
#!/usr/bin/env zsh
#
toclean=${1}
while read line; do
local length=$(echo -n ${line} | \wc -m)
if [[ ${length} -ge 50 ]]; then
local match=$(echo ${line} | \awk '{print $1}')
local file_match=$(\rg -i ${match} * -c | \awk -F ':' '{print $1}')
local num_match=$(\rg -i ${match} * -c | \awk -F ':' '{print $2}')
if [[ $(echo ${num_match} | \wc -l) -gt 1 || $((${num_match})) -ge 2 ]]; then
else
sed -i "/${match} = /d" ${file_match}
fi
fi
done < ${toclean}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment