PIP packages example:
- wheel==0.37.1
- ansible==0.29.10
- setuptools<45
Need to get exactly delimiter to verify installed package opposite required package:
wheel==0.37.1 output "="
setuptools<45 output "<"
Please help
CodePudding user response:
Is this what you're trying to do (where file contains all 3 of your posted sample input lines just for testing with)?
$ grep -Eo '[<=] ' file
==
==
<
Original guesses:
$ awk -F'[<=] ' '{print $1}' file
wheel
ansible
setuptools
$ awk -F'[<=] ' '{print $2}' file
0.37.1
0.29.10
45
CodePudding user response:
var1="wheel==0.37.1"
var2="setuptools<45"
echo $var1 | grep -Eo '[<=] ' OUTPUT "=="
echo $var2 | grep -Eo '[<=] ' OUTPUT "<"
CodePudding user response:
You could transform the whole requirement file to something that the shell can read:
#!/bin/bash
while read -r pkg op vers
do
echo "pkg='$pkg' op='$op' vers='$vers'"
done < <(
b='[:blank:]'
sed -nE 's/'"^[$b]*([^=<>~!#$b] )[$b]*([<>=~!]=|[<>])[$b]*([^#$b] ).*"'/\1 \2 \3/p' file.req
)
