Trying Multiplying Numbers On A Line Starting With The Word "size" With A Constant Variable Across 181 Text Files
Solution 1:
If you use EmEditor, you can use the Replace in Files feature of EmEditor. In EmEditor, select Replace in Files on the Search menu (or press Ctrl + Shift + H), and enter:
Find: (?<=\s)size(.*?)(\d+)
Replace with: \J "size\1" + \2 / 2
File Types: *.txt
(or file extension you are looking for)
In Folder: (folder path you are searching in)
Set the Keep Modified Files Open and Regular Expressions options (and Match Case option if size
always appears in lower case),
Click the Replace All button.
Alternatively, if you would like to use a macro, this is a macro for you (you need to edit the folder path):
editor.ReplaceInFiles("(?<=\\s)size(.*?)(\\d+)","\\J \x22size\\1\x22 + \\2 / 2","E:\\Test\\*.txt",eeFindReplaceCase | eeFindReplaceRegExp | eeReplaceKeepOpen,0,"","",0,0);
To run this, save this code as, for instance, Replace.jsee
, and then select this file from Select... in the Macros menu. Finally, select Run Replace.jsee in the Macros menu.
Explanations:
\J
in the replacement expression specifies JavaScript. In this example, \2
is the backreference from (\d+)
, thus \2 / 2
represents a matched number divided by two.
References:EmEditor How to: Replace Expression Syntax
Post a Comment for "Trying Multiplying Numbers On A Line Starting With The Word "size" With A Constant Variable Across 181 Text Files"