Created
December 31, 2018 14:33
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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