Skip to content

Instantly share code, notes, and snippets.

@peeyushsrj
Created July 19, 2021 13:57
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 peeyushsrj/932f9710d2e695d11f8c4989f8e8f3d9 to your computer and use it in GitHub Desktop.
Save peeyushsrj/932f9710d2e695d11f8c4989f8e8f3d9 to your computer and use it in GitHub Desktop.
Print unused packages in python scripts
# bash pyunused.sh filename.py
s=$(cat $1 | grep import | grep as | awk '{print $4}')
t=$(cat $1 | grep import | grep -v as | awk '{print $2}')
echo "Following unused packages"
echo "-------------------------"
for el in $s; do
count=$(cat $1 | grep $el | wc -l)
if (( ${count} == 1 )); then
echo $el
fi
done
for el in $t; do
count=$(cat $1 | grep $el | wc -l)
if (( ${count} == 1 )); then
echo $el
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment