I have a file, conda_env.txt, resulting from saving the stdout of conda list
. It has the following structure.
conda_env.txt
# packages in environment at /scratch/hello/anaconda3:
#
# Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py37_0
absl-py 0.7.1 pypi_0 pypi
alabaster 0.7.12 py37_0
anaconda-client 1.7.2 py37_0
anaconda-navigator 1.9.7 py37_0
anaconda-project 0.8.2 py37_0
annoy 1.14.0 pypi_0 pypi
I would like to conda install
all the packages listed in this file, with version specified.
My idea is to for loop over all lines (starting from the 4th line), get the value from the first and second field, and save them into PACKAGE
and VERSION
, and install the package by calling conda install $PACKAGE=$VERSION
(for example, conda install pandas=0.20.3
I would like to write a shell script to do this. I have written a demo file just to read the ith line and it's second field:
#!/bin/bash
LINES=$(wc -l < conda_env.txt)
for i in {4...10}
do
awk -F '|' 'NR==${i}{print $2}' conda_env.txt
done
and it gives me error: awk: bailing out at source line 1
.
Any idea what is going wrong here and how to do it correctly?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…