• Login
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.
  • T
    Thomas Klinghan
    last edited by May 9, 2024, 7:16 PM

    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

    A T 2 Replies Last reply May 9, 2024, 8:22 PM Reply Quote 1
    • A
      Alan Kilborn @Thomas Klinghan
      last edited by Alan Kilborn May 9, 2024, 8:40 PM May 9, 2024, 8:22 PM

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

      T 1 Reply Last reply May 12, 2024, 8:31 AM Reply Quote 4
      • T
        Terry R @Thomas Klinghan
        last edited by Terry R May 9, 2024, 8:32 PM May 9, 2024, 8:29 PM

        @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

        A T 2 Replies Last reply May 9, 2024, 8:42 PM Reply Quote 5
        • A
          Alan Kilborn @Terry R
          last edited by May 9, 2024, 8:42 PM

          @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
          • T
            Thomas Klinghan @Alan Kilborn
            last edited by May 12, 2024, 8:31 AM

            @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
            • T
              Thomas Klinghan @Terry R
              last edited by May 12, 2024, 8:32 AM

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

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