maufonfa
maufonfa

Reputation: 92

Sed to show only matching group is not working

I make this regular inside a file and it shows line:

sed -n "/href=\"\(openswitch-disk-image-genericx86-64-0.1.0\+.*\.tar\.gz\)\"/p" index.html

But if I do this it shows nothing:

sed -n "s/href=\"\(openswitch-disk-image-genericx86-64-0.1.0\+.*\.tar\.gz\)\"/\1/g" index.html

What am I doing wrong here?

Upvotes: 0

Views: 51

Answers (2)

maufonfa
maufonfa

Reputation: 92

I ended up using perl -nle like this:

perl -nle 'print $1 if /href="(openswitch-disk-image-genericx86-64-0.1.0+[0-9]+.tar.gz)"/' index.html

Upvotes: 1

glenn jackman
glenn jackman

Reputation: 246774

I'm not sure how to bend sed to do that. However grep's -o flag is made just for this

grep -o "openswitch-disk-image-genericx86-64-0.1.0\+.*\.tar\.gz" index.html

It's not clear if you want "one or more zeros" or "zero followed by plus"

Upvotes: 0

Related Questions