0

I have one line of different words stored in a txt file

N/A 9.0 Yes Yes N/A N/A N/A N/A 8.8 Yes Yes N/A N/A N/A N/A 8.7 Yes Yes N/A N/A N/A N/A 9.2 Yes Yes Yes Yes Yes Yes 9.1 Yes Yes Yes Yes Yes Yes 9.0 Yes Yes Yes Yes Yes Yes 8.8 Yes Yes Yes Yes Yes Yes 8.7 Yes Yes Yes Yes Yes Yes 22.04 Yes Yes Yes Yes Yes Yes  AKS  Microsoft Azure  v1.27 EKS  Amazon v1.27 Amazon Linux 2 is certified

I want to capture the part after "Azure" until the first whitespace - that is the version number without the "v".

My (gnu) sed command is as follows

cat out.txt | sed -E "s/.*Azure\s+v(.*?)\s+.*/\1/"

In regex101 it works as it should, but in my terminal output I get this

1.27 EKS  Amazon v1.27 Amazon Linux 2 is

It looks that the rest of the line after the the version number, up to "certified", is not consumed.

What am I missing? Thank you.

0

1 Answer 1

2

.* is greedy even under -E, the ? doesn't change that (it's a Perl and PCRE feature).

Fortunately, you don't need it: you know only non-whitespace should be matched.

sed -E 's/.*Azure\s+v(\S+)\s+.*/\1/'
#                     ~~~
0

You must log in to answer this question.

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