Community
    • Login

    Replace the space between 2 numbers with a slash

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 1.4k Views 1 Watching
    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.
    • Thomas KlinghanT Offline
      Thomas Klinghan
      last edited by

      Hello
      I have a textfile with numbers in two columns. in the first column is ID number and in the second column is subnumber to the ID. However, not every ID has a sub-number. The problem now is that I have to replace the spaces between the ID and the sub-number with a /. Where there is no sub-number, no / should be created. With search & replace you can replace all spaces with a /, but that doesn’t help me. Unfortunately I can’t find a quick and easy solution. Maybe someone can help me.

      I can create a few lines with the commands \b ^ $ {n,m}, but I always get an error.

      Example

         440     4
        1727   
         671     1
         458   
          40     3
         909     2
          64   
          49     1
        1906   
         628     1
        2560   
        1521   
        1522   
        1523   
        2633    15
      

      The Results should look like this

      440/4
      1727
      671/1
      458
      40/3
      909/2
      64
      49/1
      1906
      628/1
      2560
      1521
      1522
      1523
      2633/15
      

      Thanks so much for help

      Alan KilbornA Terry RT 2 Replies Last reply Reply Quote 1
      • Alan KilbornA Offline
        Alan Kilborn @Thomas Klinghan
        last edited by Alan Kilborn

        @Thomas-Klinghan said in Replace the space between 2 numbers with a slash:

        I’d try:

        Find: (\d+)\h+(\d+)
        Replace: $1/$2
        Search mode: Regular expression

        and then use the command to remove leading whitespace from all of the lines.

        LATER EDIT: added forgotten / between $1 and $2. :-)


        I can create a few lines with the commands \b ^ $ {n,m}, but I always get an error.

        I’ve no idea at all what that means.

        Thomas KlinghanT 1 Reply Last reply Reply Quote 4
        • Terry RT Offline
          Terry R @Thomas Klinghan
          last edited by Terry R

          @Thomas-Klinghan

          My solution is a bit different from @Alan-Kilborn , for one I do insert the / character as requested (not now that he has adjusted his regex). I also noted the lines with only the first number had additional spaces behind which appear to have been removed, so my regex also does that.

          Find What:(?-s)(\d+)\x20+(\d+)?
          Replace With:${1}(?{2}/${2})

          Terry

          Alan KilbornA Thomas KlinghanT 2 Replies Last reply Reply Quote 5
          • Alan KilbornA Offline
            Alan Kilborn @Terry R
            last edited by

            @Terry-R said in Replace the space between 2 numbers with a slash:

            My solution is a bit different from

            Yea, Terry has a pretty good solution here.
            Aside from forgetting the / (for some reason I thought this was a replace-multiple-space-with-one-space problem), I also didn’t notice trailing spaces (I didn’t copy the data, I just visually inspected it).

            1 Reply Last reply Reply Quote 1
            • Thomas KlinghanT Offline
              Thomas Klinghan @Alan Kilborn
              last edited by

              @Alan-Kilborn said in Replace the space between 2 numbers with a slash:

              LATER EDIT: added forgotten / between $1 and $2. :-)

              it works :-)
              Thanks

              1 Reply Last reply Reply Quote 0
              • Thomas KlinghanT Offline
                Thomas Klinghan @Terry R
                last edited by

                @Terry-R nice, it works, thanks :-)

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors