Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Add numbers to certain word?

    Help wanted · · · – – – · · ·
    3
    4
    102
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sagee schachter
      sagee schachter last edited by

      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.7801

      I 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.7801

      Is it possible? can I make a selection to which it would apply?

      thanks

      1 Reply Last reply Reply Quote 0
      • PeterJones
        PeterJones last edited by

        @sagee-schachter ,

        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.

        1 Reply Last reply Reply Quote 2
        • sagee schachter
          sagee schachter last edited by

          aha
          I see.

          ok thanks for the elaborate answer.

          cheers

          1 Reply Last reply Reply Quote 0
          • Ekopalypse
            Ekopalypse last edited by

            @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

            1 Reply Last reply Reply Quote 3
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors