• Login
Community
  • Login

Combining offset lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 2 Posters 286 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.
  • B
    Brennan OBrien
    last edited by Oct 29, 2022, 1:36 PM

    Hi all – got great advice on my last problem that worked perfectly. On to a new problem!

    I have the following text repeating throughout a file.

    *AC*
    
    *PD*
    
    *MD*
    
    *HP*
    
    *19*
    
    *17*
    
    *13*
    
    *92*
    

    What I am trying to get to is recombining the lines into the correct ‘column’, so that the output end up looking like this:

    *AC**19*
    *PD**17*
    *MD**13*
    *HP**92*
    

    The lines to combine together are always 8 lines apart from one another – but I’m not sure how to correctly identify the block and then resort it into the right order. Any guidance from this wise group?

    Thanks!

    1 Reply Last reply Reply Quote 0
    • B
      Brennan OBrien
      last edited by Oct 29, 2022, 1:38 PM

      I should also mention the text block is scattered throughout other text – but it always starts with AC by itself on a line.

      N 2 Replies Last reply Oct 29, 2022, 2:30 PM Reply Quote 0
      • N
        Neil Schipper @Brennan OBrien
        last edited by Oct 29, 2022, 2:30 PM

        @Brennan-OBrien

        This solution makes no assumptions about the contents of each of the 8 4-character fields; they can even be spaces. It does however rigidly require that no trailing whitespace is present on any of the 8 lines.

        Fi: (.{4})\R\R(.{4})\R\R(.{4})\R\R(.{4})\R\R(.{4})\R\R(.{4})\R\R(.{4})\R\R(.{4})\R
        Re: \1\5\r\n\2\6\r\n\3\7\r\n\4\8\r\n

        Do you know how to run Find & Replace using a regex?

        Place the caret at file start, or at least before the first occurrence of these sparse octets you’re combining.

        Start with single replaces until you are satisfied it’s doing what you hope, then you can issue a Replace All.

        1 Reply Last reply Reply Quote 2
        • N
          Neil Schipper @Brennan OBrien
          last edited by Oct 29, 2022, 2:44 PM

          @Brennan-OBrien said in Combining offset lines:

          but it always starts with AC by itself on a line.

          I failed to work that in to my solution, but it may work fine as is.

          In any event, the change to the Find expression would be to replace the first parenthesized chunk with (\*AC\*).

          B 1 Reply Last reply Oct 29, 2022, 3:11 PM Reply Quote 0
          • B
            Brennan OBrien @Neil Schipper
            last edited by Oct 29, 2022, 3:11 PM

            @Neil-Schipper
            Thanks, that worked wonders! I had some of the 8th item containing 3 and 4 digits, but changing the last {4} to {5} and {6} respectively solved it. Thank you!!

            N 1 Reply Last reply Oct 29, 2022, 3:29 PM Reply Quote 2
            • N
              Neil Schipper @Brennan OBrien
              last edited by Oct 29, 2022, 3:29 PM

              @Brennan-OBrien said in Combining offset lines:

              changing the last {4} to {5} and {6} respectively solved it

              Good to hear. It could also have been dealt with by using {4,6} which would handle all 3 cases in one go. (Speaking of which, with this problem fresh in your mind, it might be a good time to peruse the regex documentation just enough to identify the pieces that were used in the solution expressions.)

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