Community

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

    insert increasing number before/after specified word

    Help wanted · · · – – – · · ·
    4
    5
    75
    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.
    • SilentBronyRain
      SilentBronyRain last edited by

      I need to insert a number every time selected word appears in the document.
      Example insert it after every “Polka:”
      like 0 , 1 , 2 , 3 etc

      Thanks for the advice

      {"They":{Blob:"text",Info:{Samba:1}}},
      {"me":{Blob:"text",Info:{Polka:1}}},
      {"Him":{Blob:"text",Info:{Rumba:1}}},
      {"She":{Blob:"text",Info:{Polka:1}}},
      {"me":{Blob:"text",Info:{Polka:1}}},
      {"They":{Blob:"text",Info:{Rumba:1}}},
      {"me":{Blob:"text",Info:{Polka:1}}},
      
      Lycan Thrope Terry R 2 Replies Last reply Reply Quote 0
      • Lycan Thrope
        Lycan Thrope @SilentBronyRain last edited by

        @SilentBronyRain ,
        You can start here.

        Alan Kilborn 1 Reply Last reply Reply Quote 1
        • Alan Kilborn
          Alan Kilborn @Lycan Thrope last edited by

          @Lycan-Thrope said:

          You can start here.

          I think you gave the wrong link.


          @SilentBronyRain said:

          I need to insert a number every time selected word appears in the document.

          Example insert it after every “Polka:”

          like 0 , 1 , 2 , 3 etc

          The solution to your request will need to involve scripting.

          You can start HERE.

          Lycan Thrope 1 Reply Last reply Reply Quote 4
          • Lycan Thrope
            Lycan Thrope @Alan Kilborn last edited by

            @Alan-Kilborn ,
            Of course, you’re right. I didn’t catch that it’s more than just a S/R regex in the example, but, the regex can’t hurt. :)

            1 Reply Last reply Reply Quote 0
            • Terry R
              Terry R @SilentBronyRain last edited by

              @SilentBronyRain said in insert increasing number before/after specified word:

              I need to insert a number every time selected word appears in the document.

              As well as a scripting option it can also be achieved with regular expressions and other built-in functions:

              1. Insert line number at the beginning of each line
              2. Mark (bookmark) each line with the word Polka in it
              3. Cut the marked lines and paste into another tab
              4. Insert an increasing number at the end of each line (this can start at 0)
              5. move the just inserted line number (step #4) to the position behind the word Polka
              6. Cut/Copy these lines back into the original file, at end
              7. Sort the lines by using the line number inserted step #1
              8. Remove the line numbers

              I deliberately haven’t provided the actual commands, I will leave that for the OP to figure out. They aren’t difficult and could be a worthwhile learning experience. When inserting numbers in step #1 it’s important to tick the box “leading zeros” as otherwise sorting will not put the lines back into the original order.

              Note this works when only 1 “key word” is on each line. It would be possible to re-work the above process with multiple key words on each line but that would be a complicated exercise.

              Terry

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