Replace specific part of the line AFTER the match
-
Hello guys,
could you please help me with this little editing problem?
A have text file, in which I need to find all hits of a specific string and then I need to edit a part of the line which follows the searched string. Text file is formatted so the positions on the line of the searched and to-be-replaced strings are the same.
Is it somehow possible with regular expressions?
Thank you very much! -
@Hynek-Kalhous
Yes, if your search string is unique and the number of digits
between the search term and the term to be replaced is
consistent, you can do something like thisfind:
(?<=Z115 65241.{XXX}).{5}
replace:WHATEVER
That would mean I search for
Z115 65241
and the following
XXX (must be replaced by your concrete number) characters
and get the next 5 characters (.{5}
like 82302), which I replace bywhatever
. -
@Ekopalypse said in Replace specific part of the line AFTER the match:
(?<=Z115 65241.{XXX}).{5}
Thank you very much! It will do the job.
But…would it be possible to improve it a little bit? It would be nice to have one condition there - I would like to replace the 5 characters only if they have specific value. Is it possible to do it somehow easily?
Thanks again! -
@Hynek-Kalhous
yes, replace
.{5}
by that specific number. -
Thank you for answering my dumb questions! It all worked well.
-
@Hynek-Kalhous - no problem, happy to help. :-)