Thomas
Thomas

Reputation: 13

How to extract from string all words between double quotes using SED

I'm trying to use a regexp, like

.*?"([^"]+).*?"/g

to extract all words between double quotes from string. For example from:

< Header param1="1" param2="2" param3="" param4="" param5=5 param6="6" >

I would like to get:

1 2 6

Yes, I know that I can use grep, but it is necessary do it by sed

Upvotes: 1

Views: 684

Answers (1)

Ed Morton
Ed Morton

Reputation: 204259

There is no BRE or ERE than can do what you want so it can't be done in one regexp with sed. You CAN do this in sed instead if that's acceptable:

$ sed -E 's/^[^"]*"|"[^"]*$//g; s/"[^"]+"/ /g; s/ +/ /g' file
1 2 6

Upvotes: 1

Related Questions