Skip to content

Instantly share code, notes, and snippets.

@stroehleina
Created April 12, 2021 06:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stroehleina/b9498a2c61d422f818aed0c83ce7de44 to your computer and use it in GitHub Desktop.
Save stroehleina/b9498a2c61d422f818aed0c83ce7de44 to your computer and use it in GitHub Desktop.
Function that can be added as an alias to your ~/.bashrc to find all conda environments that contain a particular package (and optionally version)
#Usage: conda-find.sh my-lost-package my-version
conda info --envs |
grep -v "#" |
sed 's/\s\+/\t/' |
cut -f2 |
sed '/^$/d' |
sed 's/^\*\s\+//' |
while read line; do
conda list -p $line |
grep -v "#" |
awk -v env=$line '{print env"\t"$0}' ;
done |
awk -v look=$1 -v ver=$2 '{if($2 == look){if(ver != ""){if($3 == ver){print $0}}else{print $0}}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment