2

My lines look like this:

a;b;c;d
e;f;g;h
i;j;k;l;m;n;o;p

What i want is this:

a;b;c;-d
e;f;g;-h
i;j;k;l;m;n;o;-p

I want to add a minus after the last appearance of a semicolon. Any help is appreciated, thanks.

1 Answer 1

4
  • Ctrl+H
  • Find what: ^.+;\K.+$
  • Replace with: -$0
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

^       : beginning of line
  .+    : 1 or more any character but newline, greedy
  ;     : a semicolon
  \K    : forget all we have seen until this position
  .+    : 1 or more any character but newline
$       : end of line

Replacement:

-       : a dash
$0      : the whole match

Result for given example:

a;b;c;-d
e;f;g;-h
i;j;k;l;m;n;o;-p
3
  • As an alternate solution, a macro can be recorded for first line and then can be executed till end of file.
    – Sandeep
    Jun 12, 2018 at 8:56
  • @Sandeep: May be, but I'm not sure it is simpler. How do you select the last semicolon in the macro?
    – Toto
    Jun 12, 2018 at 13:41
  • @Toto: This is actually very simple but it cannot be saved for future sessions. I follow these steps. From start of first line, search for ; and then press HOME. Now start recording macro. Press END, SHIFT + F3 (to search last ;). Press Right arrow and type -. Press DOWN and HOME. Now, stop recording and run macro till end of file. It looks dirty but hardly takes few seconds.
    – Sandeep
    Jun 12, 2018 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .