Add numbers to certain word?
-
Hey there,
not familiar with notepad so much…I’ve got a gcode file like this:
G1 X172.523 Y248.597 E3818.7309
G1 X170.667 Y143.197 E3927.8915
G1 X168.811 Y143.197 E3929.7801I want to subtract 1 (for example) from each X in every line.
like this:
G1 X171.523 Y248.597 E3818.7309
G1 X169.667 Y143.197 E3927.8915
G1 X167.811 Y143.197 E3929.7801Is it possible? can I make a selection to which it would apply?
thanks
-
Search and replace, even in the powerful regular expression mode, doesn’t have generic math built in, so with just Notepad++, it is not possible to do.
You could use Notepad++ to write up a utility in your favorite programming language, and have that script do the replacement. (i think it would take less than 50 lines of perl or python to do it, for example; probably much less: yeah, perl has a oneliner that would do it:
perl -pi -e "m/X([+-]?\d[\d\.]+)/; my$x=$1; my$xx=$x-1; s/X$x/X$xx/g" FILENAME
– and just change the formula for$xx
if you want a different math transformation; python could probably do it in a few lines inside a for loop; 50 was an upper bound, and probably way too high)Or, if you have the PythonScript or LuaScript or similar plugin for Notepad++, you could write a script for one of those plugins that runs inside the Notepad++ environment and can edit the active file directly inside Notepad++. if you’re willing to do that, install the plugin, read some docs, take a crack at it; if you’re having difficulty, show us what you tried, and we’ll probably be able to help you finish it off. But this isn’t a code-writing service, so there’s a lower chance that you’ll get someone to write it for you from scratch.
But really, the answer is that Notepad++ itself doesn’t do this.
-
aha
I see.ok thanks for the elaborate answer.
cheers
-
@PeterJones said in Add numbers to certain word?:
i think it would take less than 50 lines of perl or python to do it
That’s for sure :-)
c3RhcnRfbGluZSwgZW5kX2xpbmUgPSBlZGl0b3IuZ2V0VXNlckxpbmVTZWxlY3Rpb24oKQ0Kc3RhcnRwb3MgPSBlZGl0b3IucG9zaXRpb25Gcm9tTGluZShzdGFydF9saW5lKQ0KZW5kcG9zID0gZWRpdG9yLmdldExpbmVFbmRQb3NpdGlvbihlbmRfbGluZSkNCmVkaXRvci5yZXJlcGxhY2UoJyg/PD1YKShbKy1dP1xkW1xkXC5dKyknLCBsYW1iZGEgbTogZmxvYXQobS5ncm91cCgxKSktMSwgMCwgc3RhcnRwb3MsIGVuZHBvcyk