Find and Replace
-
Is there a way to do a replace by column number
example - i have a txt file and i need to replace whatever characters are incolumns 220-222 in each row with —Is there a way to do that? regular find/replace wont work because each line is different in those spaces
-
Hello Linda,
regular find/replace wont work because each line is different in those spaces
I don’t understand very well ? May be, your text contains some tabulation character, which don’t match the same physical space length ?
If so, I would advice you, to replace, first, any tabulation by the corresponding amount of space characters, with the menu command Edit - Blank Operations - TAB to Space
Then, taking your previous example, just perform a simple regular search/replace operation like, for instance :
-
SEARCH =
^.{219}\K...
and REPLACE =EMPTY
to delete from the 220th till the 222th characters -
SEARCH =
^.{219}\K...
and REPLACE =ABC
to insert a fixed string between the 220th column till the 222th column -
SEARCH =
^.{219}\K(...)
and REPLACE =[\1]
to surround the characters, between the 220th and the 222th, with two square brackets
IMPORTANT :
Due to the special
\K
syntax, you must use a global replacement, clicking on the Replace All button
If you prefer use a step-by-step replace operation, the different S/R, above, should be rewritten as below :
-
SEARCH =
^(.{219})...
and REPLACE =\1
to delete from the 220th till the 222th characters -
SEARCH =
^(.{219})...
and REPLACE =\1ABC
to insert a fixed string between the 220th column till the 222th column -
SEARCH =
^(.{219})(...)
and REPLACE =\1[\2]
to surround the characters, between the 220th and the 222th, with two square brackets
Hope that helps you a bit !
Best Regards,
guy038
P.S. :
The nice thing, about the
\K
syntax, is that anything that matched before the\K
form, is forgotten by the regex engine! So, in the examples above, the matched string(...)
is, ONLY, the three characters, at positions 220, 221 and 222 :-) -