Community
    • Login

    random replace string for a limited amout of accourenses

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 316 Views
    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.
    • ciucaandreiC
      ciucaandrei
      last edited by

      Hi,

      I have multiple files and I want to replace a certain word randomly in a string a limited amount of times.
      The replace would have to search the files randomly and then replace the first 20 accourenses

      For example if every line of every file would be in a database, I would need the command : update table set continut = REPLACE(continut, ‘word1’, ‘word’) order by rand limit 20

      Thanks

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @ciucaandrei
        last edited by

        @ciucaandrei ,

        Search-and-replace cannot randomize the list of files to search. And search-and-replace doesn’t have a counter that would work exactly like you showed (you can tell it to repeat part of the same regex N times, so it can count to some extent… but that’s counting within a single match, not counting and only doing a replacement for the first N matches). So you would have to manually pick your “random file” and then do the search/replace once in that file; then do that again N times.

        The way you described it, it sounds like a programming challenge, not a text editor feature. And the purpose of this forum is to help each other use the existing features of Notepad++ to the best of its ability, not do other people’s programming for them.

        If you want to solve it in programming, you could type the code to do that in Notepad++, which is one of its primary purposes. And if you wanted to, you could use one of the scripting plugins, like PythonScript, where the script would run on the files that are opened in Notepad++… but even then, it’s still essentially a programming task, and we are not a programming forum.

        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors