I have an xml file with these lines (among others):
#Env=DEV2,DEV3,DEV5,DEV6
#Enter your required DEV environment after the ENV= in the next line:
Env=DEV6
I need to:
- Verify that the text after
ENV=
is of the patternDEV{1..99}
- extract the number (in this case, 6) from the line
ENV=DEV6
to some environment variable
I know a bit of awk and grep, and can use those to get the number, but I'm thinking of Sed, which I'm told matches patterns nicer than awk and takes less time. Also, I'm concerned about long long lines of greps matching the beginning of the line for that particular Env= .
How would I go about doing it with Sed? would I get away with a shorter line?
I'm a sed newbie, read a bunch of tutorials and examples and got my fingers twisted trying to do both things at the same time...
Input:
Output:
To store it into any variable:
You can used
sed
asYou can directly use the above command in
export
command as(or) its pretty straight forward with
perl
Can use
grep
also ifpcre
regex is available-x
match whole line-o
output only matching text-P
usepcre
regexEnv=DEV\K
matchEnv=DEV
but not part of output[1-9][0-9]?
range of1
to99
I suggest with GNU sed:
Output:
In awk. First some test cases: