Is it a bug ... or is there an explanation?
Please note that I'm not looking for a workaround but rather why the order of -ir
and -ri
matters ...
Imagine the following data stored in file data.txt
1, StringString, AnotherString 545
2, StringString, AnotherString 723
3, StringString, AnotherString 610
4, StringString, AnotherString 118
5, StringString, AnotherString 482
Desired string transformation
Replace "StringString" with "Strung"
With the following code
sed -ir 's/String+/Strung/g' data.txt <-- won't work
sed -ri 's/String+/Strung/g' data.txt <-- will work
I don't see any reason why the order of option flags would matter? Any explanations?
Sidenotes: The switch -i
"edits the file in place" while -r allows "extended
regular expression" (allowing the +
operator). Running sed 4.2.1
Dec. 2010 on Ubuntu 12.10.
The select flag permits an executable to request and be part of SED protection during the select mode of systemwide SED operation, whereas the exempt flag permits an executable to request for an exemption from the SED mechanism. These executables are not enabled for execution disable on any of the process memory areas.
r is used to read a file and append it at the current point. The point in your example is the address /EOF/ which means this script will find the line containing EOF and then append the file specified by $thingToAdd after that point. Then it will process the rest of the file.
Sed reads the input stream until it finds the new line character \n . Then it will take all the data it read so far and place it into a buffer without newline character \n . Most of the commands operate on this data present in the buffer. This buffer is known as pattern buffer.
When doing -ir
you are specifying that "r" should be the suffix for the backup file.
You should be able to do -i -r
if you need them in that order
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With