Home > Mobile >  Replace a word only on specific line # (Regex)
Replace a word only on specific line # (Regex)

Time:07-10

Within a large file I need to replace one word only on specific lines. Say, on line 25, 55, 181, 1448, and so forth about 2000 times.

I started doing it manually using "go to" line and replacing the word. Is there a way to do it automatically, even if I have to change the value for every instance? It will still be faster.

CodePudding user response:

Maybe you can try something like this:

\A(?:^.*$\n){5}\K^.*$

Where 5 are the previous lines. So 5 means you want to get line number 6.

Working Example: https://regex101.com/r/QuDon0/1

  • Related