A requirements file pip contains all the packages installed in Python, so that the file can be used elsewhere and rebuild the original programming environment.
A requirements file looks like this:
alabaster==0.7.9
arrow==0.8.0
awesome-slugify==1.6.5
Babel==2.3.4
binaryornot==0.4.0
blessings==1.6
What I want is to remove the part that indicates the version, in the case of the first line alabaster==0.7.9
, delete the part ==0.7.9
and leave only alabaster
.
I understand that finding a match creates two groups, but I can not make it work. I'm trying it in ubuntu using awk as follows.
When I ask for the first group:
$ awk -F"==" '{print $1}' base.txt
I get this:
alabaster==0.7.9
arrow==0.8.0
awesome-slugify==1.6.5
that is, the file is repeated.
When I ask for the second group with
$ awk -F"==" '{print $2}' base.txt
I only get 50 blank lines.
ADDITION:
Now I'm looking for this pattern (\w+)(==.)
with what I do two match groups, I'm interested in the first one. But if the package is called python-mimeparse
there is no match anymore. You should be able to add scripts in case a package is called paquete_python
or paquete-python
.
Addendum 2
This expression (.+)(==)(.+)
finds three groups, the first is the package (which is what I'm looking for) and the third is the version. Now I just need to know how to use it in awk
.
third edition
I published an answer that solves the problem in Python, but the idea is that the solution is applied with some other tool such as awk
, gawk
, sed
or even perl
.
There are several options in this SOEN publication, but do not I have been able to use my search pattern in none. I do not get errors, but I do not get any results either.
Alguas considerations:
- I'm looking for just the name of the package , not the version
- There is no package installed, so there is nothing to update
- The solution can use another tool, such as
sed
orgrep