Want to underline/mark the last instance of a pattern on each line using ed(1)?
g/pattern/t.\
s/\(.*\)\(pattern\).*/\1\
\2/\
s/./^/g\
-s/./ /g\
j
puts a sequence of "^"s under the last match on each line.
@ed1conf Can you give an example of pattern this addresses?
@akpoff Can use it to underline (or under-caret?) text. Want to see the last instance of "Mercutio" on each line as you review your text of Romeo & Juliet?
g/Mercutio/t.\
s/\(.*\)\(Mercutio\).*/x\1\
\2/\
s/./^/g\
-s/./ /g\
s/^ //\
j
@ed1conf Nevermind. I got it to fail using the first pattern, and work with the second.
Nice work!
Small issue if the only instance of /pattern/ falls at the beginning of the line. This should fix it:
g/pattern/t.\
s/\(.*\)\(pattern\).*/x\1\
\2/\
s/./^/g\
-s/./ /g\
s/^ //\
j
Otherwise the "s/./ /g" fails.