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

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.