I have a requirements.txt file with versions listed e.g.

# requirements.txt

For versions with == PIP installs that exact version but for those with >= it installs the highest it can based on other packages. I would like to save the installed version of all packages with >= in a new file (or if possible directly overwrite the ones in the original file), so for example the result could be:

# requirements_updates.txt

I've tried stuff like cat requirements.txt | grep -Po ".*?(?=>=)" | xargs -I "python -m pip freeze | grep %" | grep -Po "(?<===).*?(?=$)" during testing (and you should probably ignore that) but it stops producing output after multiple pipes, and it also doesn't take into account packages with == which should be copied blindly. I prefer a command over a script so it is easy to share and use in already running Docker containers.

  • That cat | grep | xargs is a script. It's code in the shell language. If you can run that command / script in your "docker container", there shouldn't be anything stopping you from running any other script / command, whether they're written on one line or more. Dec 21, 2020 at 14:03

1 Answer 1


You could do something like:

python -m pip freeze |
  awk '!x              {v[$1] = $2; next}
       NF>1 && $1 in v {$0 = $1"=="v[$1]}
      ' FS='==' - x=1 FS='>=' requirements.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .