Skip to content

Instantly share code, notes, and snippets.

@peeyushsrj
Created July 19, 2021 13:57
Show Gist options
  • Select an option

  • Save peeyushsrj/932f9710d2e695d11f8c4989f8e8f3d9 to your computer and use it in GitHub Desktop.

Select an option

Save peeyushsrj/932f9710d2e695d11f8c4989f8e8f3d9 to your computer and use it in GitHub Desktop.

Revisions

  1. peeyushsrj created this gist Jul 19, 2021.
    19 changes: 19 additions & 0 deletions pyunused.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # 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