Is it possible to create a diff patchfile that will edit lines themselves, rather than replacing an entire line?
For example, I have the following line:
<foo:ListeningPortBar>3423</foo:ListeningPortBar>
and I want to change this to:
<cat:LoremIpsum>3423</cat:LoremIpsum>
That is, I want to change the text around the actual port number, but preserve the port number – I need to apply this patch across a number of files, all with different port numbers – I simply want to change the tags, keeping whatever port number is in there currently.
How can you achieve this please?
Thanks,
Victor
It doesn’t really matter if a patch replaces the entire line or just characters in the line (the end result is the same, no…?), but I don’t think this is a “patch” question. See below for a simpler solution using “sed”.
For example, assume:
Then, literally the patch would be:
This patch file could be used as a template, modified with correct values for all your files that need to be updated, and applied to all the files individually. That sounds like more work than necessary.
On the other hand, just use “sed”:
Since you have XML, using xsltproc is another alternative, but again probably overkill for this simple search-and-replace task.
To use this in a script, you’d do something like (replacing “etc/etc” with the sed above):
…and then verify that the “.bak” files are actually different than the modified files.