I am new to using regex and having some issues understanding how to extract a group from a regular expression. I have a text file (example.txt):
libstuff-example1 (>= 6.3.2),
libpackage-example2 (>= 5.2.1),
libtest-example3 (>= 5.2.1)
I am trying to extract the "5.2.1" only from the libpackage line and put it into a variable for a bash script. I have tried doing
cat example.txt | grep -oP "libpackage-[a-z- (>=]+(.*)[)],"
But it gives me the entire line instead of that "5.2.1" section. How do I extract the first group from that line so I only get "5.2.1"?
grep
doesn't have any way of accessing groups.-o
prints the entire match.