I do context constrained global edits in ed with the following technique: 1) identify a character that does NOT appear in the first column of any line (so far the character '@' usually works) 2) mark the lines I want to make the global edit on by inserting that character at the start of each such line 3) globally make the edit on each line starting with that character 4) remove that leading character (one more global edit).
For example, to replace every "Fido" with "Rufus" in all lines with the word "apple", except those lines also with the word "banana": # verify no line starts with '@' g/^@/ # insert '@' before each line with "apple" g/apple/s/^/@/ # delete the '@' if "banana" also on those lines g/^@.*banana/s/@// # replace Fido with Rufus on chosen lines g/^@.*Fido/s/Fido/Rufus/ # clean up '@' marker character g/^@/s/// This way of marking lines to edit works for most any selection criteria. One can easily keep searching the file to ensure that the lines that one wants to modify are marked, and no other lines. To show lines around a match, use syntax such as in this example: g/Fido/-2,+2p When I prefer such context as the default, I break down and use whatever "screen" editor I am using that decade. The "ed" editor is inherently a line editor, which with such techniques as above enables me to show _just_ the lines I want to show. Sometimes that works best, sometimes not. -- Paul Jackson [email protected]
