Community
    • Login

    Replace the space between 2 numbers with a slash

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 724 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.
    • Thomas KlinghanT
      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
        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
          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
            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
              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
                Thomas Klinghan @Terry R
                last edited by

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

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