sed ‘s_((checksum|compressed)=\”).*(\”)_\1\2_’ -i filename
I am using this command to replace the checksum and compressed filed with empty? But it didn’t change anything?
for example, I want change this line ” checksum=”XXXXX” with checksum=””, and also replace
compressed=”XXXX” with compressed=””
What is wrong with my sed command?
It’s because sed uses a funny regex dialect by default: you have to escape capturing brackets.
If you want to use “normal” regex that you’re familiar with, use the
-rflag (if you’re on unix, GNU sed) or the-Eflag (Mac OS X BSD sed):Additionally, note that you have three sets of capturing brackets in your
sed, and I think you want to change the\1\2to\1\3. (\1 containschecksum=", \2 containschecksum, and \3 contains").(For interest, here’s how you would do it without the extended-regexp (-r/-E) flag, note that capturing brackets and the OR
|are only considered in the regex sense if they are escaped:)