• Login
Community
  • Login

How to move numbers at end of line to new position in same line farther to the right I normally tab them over to

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 6 Posters 1.0k 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.
  • G
    ginger manson
    last edited by ginger manson Mar 4, 2021, 6:49 AM Mar 4, 2021, 6:48 AM

    ginger manson
    ginger manson 27 minutes ago

    Can someone please help me with batch processing a large document where I need to move all the numbers towards the end of a line to a new position? Normally I just hit tab to move them over, but as it’s a large document this would take a very long time, and I figure there has to be an easier way. They need to move out to the left to allow for artists with long names.

    EXAMPLE
    --------------------------------(Page #)

    LINE 1 Drawing Artist----------234
    LINE 2 Drawing Artist-256

    DESIRED RESULT

    LINE 2 Drawing Artist----------256

    Imagine the dashes are just spaces, otherwise I lose the formatting which gives this post context.

    If any one can help me with how to move the page numbers in multiple lines at once to the new position I want to send them to based on lines I have already shifted that would be great. Thanks for your time. :)

    E A 2 Replies Last reply Mar 4, 2021, 9:33 AM Reply Quote 1
    • E
      Ekopalypse @ginger manson
      last edited by Mar 4, 2021, 9:33 AM

      @ginger-manson

      What about using something like
      find what: (?<=Drawing Artist) (?=\d+)
      and replace with: as many spaces as you like to have
      check regular expression checkbox.

      1 Reply Last reply Reply Quote 1
      • G
        ginger manson
        last edited by Mar 4, 2021, 10:35 AM

        Unfortunately, I need something more like move numbers to set position in line so many spaces from the start because all the drawing artists names are different lengths, so no one number of spaces will correctly move over the numbers to the same set position as it varies from line to line. Thank you for the suggestion though.

        P 1 Reply Last reply Mar 4, 2021, 2:25 PM Reply Quote 0
        • P
          PeterJones @ginger manson
          last edited by Mar 4, 2021, 2:25 PM

          @ginger-manson ,

          I would do this in two stages, to keep it relatively simple.

          1. First, move all the numbers far to the right

            • FIND = \h*(\d+)\h*$
              • zero or more spaces, followed by 1 or more digits, followed by zero or more spaces then the end of line; store the digits in group#1
            • REPLACE = \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20${1}
              • the \x20 represents a space in regex; I used that to avoid ambiguity in the forum; you can just type 20 (or more) spaces rather than 20 of \x20. I throw away any spaces after the digits (just in case you had a space character you hadn’t seen).
            • SEARCH MODE = regular expression
            • REPLACE ALL
          2. Then I would reduce the number of spaces so they all line up right-aligned.

            • FIND = ^(.{36})\h*(\d)(\d)?(\d)?(\d)?$
              • I am using a trick of capturing each digit in a separate group number so that I can determine the number of digits, so I know how many spaces I need. I assume a maximum of 4 digits in the page number.
              • I assumed 36 characters on the left, plus 4 digits for the right-aligned page number. If you want a different number of columns total, then adjust the number in the {} appropriately
            • REPLACE = ${1}(?{5}:\x20)(?{4}:\x20)(?{3}:\x20)${2}${3}${4}${5}
              • looks more complicated than it is.
              • the ${1} just puts the 36 left characters from group#1 back at the start of the line
              • each of the (?{ℕ}:\x20) conditional tokens just says “if group #ℕ matched, do nothing, else include a space here in the replacement”. With three of those conditional tokens, that will allow prefixing with up to 3 spaces to right-justify the 4digit number
              • finally, the ${2}${3}${4}${5} will put in the 4-digit number (if it’s fewer digits, the last group(s) will be empty, so it will still replace correctly)
            • SEARCH MODE = regular expression
            • REPLACE ALL

          Note that in step 1, how far to the right you move the numbers depends on how wide you want it in step 2. For example, if you want 40 characters total width after step 2, so you use 36 as the quantity in step2 search, then I would do at least 36 spaces (or \x20) in the step1 replacement. I only showed 20 because it was getting excessively wide for the forum…

          If I start with

          123456789x123456789x123456789x123456789x123456789x
                                          (Page #)
          LINE 1 Drawing Artist 234
          LINE 2 Drawing Artist 256
          LINE 1 Drawing Artist 1
          LINE 2 Drawing Artist 12
          LINE 2 Drawing Artist 123
          LINE 2 Drawing Artist 1234
          LINE 1 Drawing Someone 1
          LINE 1 Drawing Someone 12
          LINE 1 Drawing Someone 123
          LINE 2 Drawing Someone 1234
          

          After the first search/replace REPLACE ALL, I get

          123456789x123456789x123456789x123456789x123456789x
                                          (Page #)
          LINE 1 Drawing Artist                    234
          LINE 2 Drawing Artist                    256
          LINE 1 Drawing Artist                    1
          LINE 2 Drawing Artist                    12
          LINE 2 Drawing Artist                    123
          LINE 2 Drawing Artist                    1234
          LINE 1 Drawing Someone                    1
          LINE 1 Drawing Someone                    12
          LINE 1 Drawing Someone                    123
          LINE 2 Drawing Someone                    1234
          

          After the second search/replace REPLACE ALL, I get

          123456789x123456789x123456789x123456789x123456789x
                                          (Page #)
          LINE 1 Drawing Artist                234
          LINE 2 Drawing Artist                256
          LINE 1 Drawing Artist                  1
          LINE 2 Drawing Artist                 12
          LINE 2 Drawing Artist                123
          LINE 2 Drawing Artist               1234
          LINE 1 Drawing Someone                 1
          LINE 1 Drawing Someone                12
          LINE 1 Drawing Someone               123
          LINE 2 Drawing Someone              1234
          

          … which has the page numbers right justified, which appears to be what you asked for.

          If that’s not what you want, try experimenting to make it match what you do want. If you cannot get it to work after experimentation, please follow the advice below to give more-detailed examples of what you have and what you want, explain the changes you made in my regex and why you thought it would make it work, and ask any specific questions.

          ----

          Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

          1 Reply Last reply Reply Quote 4
          • A
            astrosofista @ginger manson
            last edited by Mar 4, 2021, 4:15 PM

            Hi @ginger-manson

            I will suggest another approach, which requires regex and a plugin, as follows.

            First convert the spaces before the page numbers to a tab with this regular expression:

            Search: \s+(\d+|\(Page #\))$
            Replace: \t$1

            Put the caret at the very beginning of the document, select just the Regular Expression mode and click on Replace All.

            Second, if not yet installed, install the Elastic TabStops plugin via Plugins Admin... In the plugin menu select Enable to get tabs aligned and then, from the same menu, select Convert TabStops to Spaces.

            That’s all. Unlike @PeterJones’s fine solution, all page numbers are aligned to the left.

            Take care and have fun!

            1 Reply Last reply Reply Quote 2
            • G
              guy038
              last edited by guy038 Nov 19, 2022, 1:49 AM Mar 4, 2021, 5:57 PM

              Hello, @ginger-manson, @ekopalypse, @peterjones, @astrosofista and All,

              Here is a general method, from within N++

              We assume a consecutive list of lines, composed of :

              • A text, of variable length, located before the number to justify

              • An integer number to be justified , located next, after some non-words chars ( could be a simple space char )

              And :

              • Let the value M be the length of the longest line of that list

              • Let’s define the filling char F to insert between the text and the number, in each line. This is generally the space char but it could be the . character, either


              In that case, we can right justify that list of numbers, at column C , with the condition C >= M, with the help of these 3 consecutive regex S/R :

              • (I) S/R

                • SEARCH $

                • REPLACE The FILLING character F, repeated C times

              • (II) S/R

                • SEARCH (?-s)^(.{C}).+

                • REPLACE \1

              • (III) S/R

                • SEARCH (\d+)(F*)

                • REPLACE \2\1

              For instance, let’s suppose you want to right justify numbers on column 60, with dot characters, then :

              • In S/R (I), the Replace with zone will contain 60 dot characters

              • In S/R (II), the search regex used will be (?-s)^(.{60}).+

              • In S/R (III), the search regex used will be (\d+)(\.*)


              OK, let’s start with that text :

              LINE 1 Drawing Artist 123456789
              LINE 2 Drawing Artist 256
              LINE 3 Drawing Artist 1
              LINE 4 Drawing Artist 12
              LINE 5 Drawing Artist 123
              LINE 6 Drawing Artist 1234
              LINE 1 A text 9876
              LINE 2 A text 528
              LINE 3 A text 7
              LINE 4 A text 1234567
              LINE 1 An other much longer text 0
              LINE 2 An other much longer text 123456789
              LINE 3 An other much longer text 123
              LINE 4 An other much longer text 01234
              

              As you can see, the longest line of that list is the line LINE 2 An other much longer text 123456789 which is 42 chars long

              So, let’s suppose that we want to right justify at this minimum column => the value C is 42 and we’ll use the space filling char so F = \x20

              First, use the View > Show Symbol > Show White Space and TAB to clearly see the space chars !

              With the first regex S/R, we add 42 filling characters at end of each line

              • SEARCH $

              • REPLACE Write 42 SPACE chars

              We get that text :

              LINE 1 Drawing Artist 123456789                                          
              LINE 2 Drawing Artist 256                                          
              LINE 3 Drawing Artist 1                                          
              LINE 4 Drawing Artist 12                                          
              LINE 5 Drawing Artist 123                                          
              LINE 6 Drawing Artist 1234                                          
              LINE 1 A text 9876                                          
              LINE 2 A text 528                                          
              LINE 3 A text 7                                          
              LINE 4 A text 1234567                                          
              LINE 1 An other much longer text 0                                          
              LINE 2 An other much longer text 123456789                                          
              LINE 3 An other much longer text 123                                          
              LINE 4 An other much longer text 01234                                          
              

              With the second regex S/R, any line is limited to its 42 first characters, only :

              • SEARCH (?-s)^(.{42}).+

              • REPLACE \1

              LINE 1 Drawing Artist 123456789           
              LINE 2 Drawing Artist 256                 
              LINE 3 Drawing Artist 1                   
              LINE 4 Drawing Artist 12                  
              LINE 5 Drawing Artist 123                 
              LINE 6 Drawing Artist 1234                
              LINE 1 A text 9876                        
              LINE 2 A text 528                         
              LINE 3 A text 7                           
              LINE 4 A text 1234567                     
              LINE 1 An other much longer text 0        
              LINE 2 An other much longer text 123456789
              LINE 3 An other much longer text 123      
              LINE 4 An other much longer text 01234    
              

              Finally, with this third regex S/R, numbers are right justified at column 42 :

              SEARCH (\d+)(\x20*)

              REPLACE \2\1

              LINE  1Drawing Artist            123456789
              LINE  2Drawing Artist                  256
              LINE  3Drawing Artist                    1
              LINE  4Drawing Artist                   12
              LINE  5Drawing Artist                  123
              LINE  6Drawing Artist                 1234
              LINE  1A text                         9876
              LINE  2A text                          528
              LINE  3A text                            7
              LINE  4A text                      1234567
              LINE  1An other much longer text         0
              LINE  2An other much longer text 123456789
              LINE  3An other much longer text       123
              LINE  4An other much longer text     01234
              

              Nice, isn’t it ?


              Let’s go back to our text, where we add four other space characters before each number, giving :

              LINE 1 Drawing Artist     123456789
              LINE 2 Drawing Artist     256
              LINE 3 Drawing Artist     1
              LINE 4 Drawing Artist     12
              LINE 5 Drawing Artist     123
              LINE 6 Drawing Artist     1234
              LINE 1 A text     9876
              LINE 2 A text     528
              LINE 3 A text     7
              LINE 4 A text     1234567
              LINE 1 An other much longer text     0
              LINE 2 An other much longer text     123456789
              LINE 3 An other much longer text     123
              LINE 4 An other much longer text     01234
              

              This time, we prefer to right justify at column 60, so the value C is 60 and use the dot as filling character => F = \. . Hence :

              With the first regex S/R, we add 60 filling dot characters at end of each line

              • SEARCH $

              • REPLACE Write 60 DOT chars

              We obtain :

              LINE 1 Drawing Artist     123456789............................................................
              LINE 2 Drawing Artist     256............................................................
              LINE 3 Drawing Artist     1............................................................
              LINE 4 Drawing Artist     12............................................................
              LINE 5 Drawing Artist     123............................................................
              LINE 6 Drawing Artist     1234............................................................
              LINE 1 A text     9876............................................................
              LINE 2 A text     528............................................................
              LINE 3 A text     7............................................................
              LINE 4 A text     1234567............................................................
              LINE 1 An other much longer text     0............................................................
              LINE 2 An other much longer text     123456789............................................................
              LINE 3 An other much longer text     123............................................................
              LINE 4 An other much longer text     01234............................................................
              

              With the second regex S/R, any line is limited to its 60 first characters, only :

              • SEARCH (?-s)^(.{60}).+

              • REPLACE \1

              and we get :

              LINE 1 Drawing Artist     123456789.........................
              LINE 2 Drawing Artist     256...............................
              LINE 3 Drawing Artist     1.................................
              LINE 4 Drawing Artist     12................................
              LINE 5 Drawing Artist     123...............................
              LINE 6 Drawing Artist     1234..............................
              LINE 1 A text     9876......................................
              LINE 2 A text     528.......................................
              LINE 3 A text     7.........................................
              LINE 4 A text     1234567...................................
              LINE 1 An other much longer text     0......................
              LINE 2 An other much longer text     123456789..............
              LINE 3 An other much longer text     123....................
              LINE 4 An other much longer text     01234..................
              

              Finally, with this third regex S/R, numbers are right justified at column 60 :

              SEARCH (\d+)(\.*)

              REPLACE \2\1

              LINE 1 Drawing Artist     .........................123456789
              LINE 2 Drawing Artist     ...............................256
              LINE 3 Drawing Artist     .................................1
              LINE 4 Drawing Artist     ................................12
              LINE 5 Drawing Artist     ...............................123
              LINE 6 Drawing Artist     ..............................1234
              LINE 1 A text     ......................................9876
              LINE 2 A text     .......................................528
              LINE 3 A text     .........................................7
              LINE 4 A text     ...................................1234567
              LINE 1 An other much longer text     ......................0
              LINE 2 An other much longer text     ..............123456789
              LINE 3 An other much longer text     ....................123
              LINE 4 An other much longer text     ..................01234
              

              Best Regards,

              guy038

              1 Reply Last reply Reply Quote 3
              • G
                ginger manson
                last edited by Mar 4, 2021, 11:35 PM

                @guy038,@ekopalypse, @ peterjones, @astrosofista

                Thank you all so much for your replies! After fiddling around and trying the first 3 methods I think I have come up with a solution which put me close enough to what I want to where I can easily finish it up without much work at all. I modified Peters code a bit

                \h*(\d+)\h*$
                \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20${1}
                ^(.{59})\h*(\d)(\d)?(\d)?(\d)?$
                ${1}(?{5}:\x20)(?{4}:\x20)(?{3}:\x20)${2}${3}${4}${5}

                A low number of numbers didn’t line up exactly where I wanted them but the overall workload of around 11,065 lines worth of tabbing say 5-6 times per line has been reduced by say 93 percent or so. And I consider that to be a major victory. @guy038 I really liked the look of what you accomplished with your method, but honestly I got lost trying to implement it. I do however thank you very much for responding. I’m sure if I was a bit more skilled at interpreting and implementing your solution it would have worked out great.

                Alan KilbornA 1 Reply Last reply Mar 15, 2021, 11:58 AM Reply Quote 3
                • Alan KilbornA
                  Alan Kilborn @ginger manson
                  last edited by Mar 15, 2021, 11:58 AM

                  @ginger-manson said in How to move numbers at end of line to new position in same line farther to the right I normally tab them over to:

                  @guy038 I really liked the look of what you accomplished with your method, but honestly I got lost trying to implement it.

                  This can be a problem sometimes with the solutions Guy offers, but hmm, in this case I just followed the steps and it worked exactly right, so I encourage the OP to try it again.

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