1

This,

echo 'memory-type="3" reference-number="1" crc="0"' | sed 's/reference-number=".*"//g'

returns:

memory-type="3" 

I want:

memory-type="3" crc="0"

What's the reg-ex to accomplish this?

White-space isn't important in the final result

1 Answer 1

3

Your problem is that .* matches the longest possible string; in your case:

memory-type="3" reference-number="1" crc="0"
                                  ↑-------↑

You want it to match only the 1.  The simplest way to do this is to match, not any number of any character, but any number of any character except for quote:

$ echo 'memory-type="3" reference-number="1" crc="0"' | sed 's/reference-number="[^"]*"//g'
memory-type="3"  crc="0"
0

You must log in to answer this question.

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