• Login
Community
  • Login

How to join some lines with desired specifications in notepad++

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 485 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.
  • A
    AliMirzaei5778
    last edited by Jun 18, 2022, 3:59 PM

    Hi everyone,
    I have data that contains many blocks. Below I have given two of these blocks as examples.

    sunday 10-may-2020 00:00 cc  71   lp 1.3  svp1.3 ts   63 +0 lr 63" SA 378 ab 104
     Int   SA/LK     hp  tp#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef# Aab 
     1112 SA 378  "   B  21#  93   6   9#  98   7  11> 104   6  11#   -       -#   92
     1112 SA 379      B  21#  29   4   3#   -       -#   -       -#   -       -#   24
     1112 SA 380 ^"   A  12#  96   3   7#  30   2   2#   -       -#   -       -#   80
     1112 SA 381  "   C  16#  38   2   3#  64   4   4#   -       -#   -       -#   67
    A=25  B=<50>  C=25
    sunday 10-may-2020 00:01 cc  71   lp 2.3  svp2.3 ts   61 +0 lr 50" SA 381 ab 73
     Int   SA/LK     hp  tp#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef# Aab
     1112 SA 378  "   B  25#  42   5   5#  65   7   9#  62   5   8#   -       -#   86 
     1112 SA 379      B  25#  31   5   4#   -       -#   -       -#   -       -#   28
     1112 SA 380 ^"   A  13#  49   3   4#  79   4   5#   -       -#   -       -#   77
     1112 SA 381  "   C  18#  73   3   6#  53   4   4#   -       -#   -       -#   74
    A=35  B=<40>  C=25
    

    I have to convert the above blocks as displayed in the following:

    sunday 10-may-2020 00:00 cc  71   lp 1.3  svp1.3 ts   63 +0 lr 63" SA 378 ab 104 Int   SA/LK     hp  tp#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef# Aab  A=25  B=<50>  C=25	
    																				 1112 SA 378  "   B  21#  93   6   9#  98   7  11> 104   6  11#   -       -#   92
    																				 1112 SA 379      B  21#  29   4   3#   -       -#   -       -#   -       -#   24
    																				 1112 SA 380 ^"   A  12#  96   3   7#  30   2   2#   -       -#   -       -#   80
    																				 1112 SA 381  "   C  16#  38   2   3#  64   4   4#   -       -#   -       -#   67
    sunday 10-may-2020 00:01 cc  71   lp 2.3  svp2.3 ts   61 +0 lr 50" SA 381 ab 73	Int   SA/LK     hp  tp#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef#  ab  cd  ef# Aab	 A=35  B=<40>  C=25 
    																				1112 SA 378  "   B  25#  42   5   5#  65   7   9#  62   5   8#   -       -#   86 
    																				1112 SA 379      B  25#  31   5   4#   -       -#   -       -#   -       -#   28
    																				1112 SA 380 ^"   A  13#  49   3   4#  79   4   5#   -       -#   -       -#   77
    																				1112 SA 381  "   C  18#  73   3   6#  53   4   4#   -       -#   -       -#   74
    

    Because I think the code may not be displayed in the desired state, I have also attached the following image.
    ![alt text](51cdb5c7-60b9-4fe5-a355-d74b0fbe414a-image.png image URL)
    Could anyone give me some suggestions on how to solve this issue?
    Regards,
    Ali

    P 1 Reply Last reply Jun 18, 2022, 5:38 PM Reply Quote 0
    • P
      PeterJones @AliMirzaei5778
      last edited by PeterJones Jun 18, 2022, 5:42 PM Jun 18, 2022, 5:38 PM

      @alimirzaei5778 said in How to join some lines with desired specifications in notepad++:

      Could anyone give me some suggestions on how to solve this issue

      Making the following assumptions:

      1. for any group of 7 lines, you always want to combine #1, #2, and #7 into the first line, and indent #3-#6 the same number of characters (see 3rd point, below)
      2. lines #2-#6 will always start with spaces, and #1 and #7 will not start with spaces
      3. You want to indent using 20 tabs and keep the space that was at the start of the line after the tabs (at least, that’s how many tabs I counted in your plaintext, and the number of indent indicators in your screenshot seemed to agree)

      With that, I would probably do it in two steps:

      1. Merge the lines so that 1,2,7 are joined into line 1 (making it groups of 5 lines instead of groups of 7 lines)
        • FIND WHAT: (?-s)(^.*)(\R)(^ .*)\2((?:^ .*\2){4})(^.*$)\2?
        • REPLACE WITH: $1$3 $5$2$4
        • MODE: Regular Expression
        • multiple REPLACE or just REPLACE ALL
      2. Indent all the lines that begin with a space (which used to be #3-#6 in the original 7-line grouping)
        • FIND WHAT: (?-s)^\x20
        • REPLACE WITH: \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\x20
        • MODE: Regular Expression
        • multiple REPLACE or just REPLACE ALL

      Note: I used \x20 to match or replace a space to make it easy to copy/paste with a space at the end of the regular expression; I used \t in the replacement to indicate a TAB character. Just copy/paste the red expressions into the appropriate field in the Replace dialog, and it will work, because those are valid regex expressions for those characters.

      ----

      Useful References

      • Please Read Before Posting
      • Template for Search/Replace Questions
      • FAQ: Where to find regular expressions (regex) documentation
      • Notepad++ Online User Manual: Searching/Regex

      -----
      PS: the reason your black box didn’t look right is because you have Notepad++ set to display tabwidth=4, but the forum is tabwidth=8; the forum is not as configurable as Notepad++ is ;-)

      A 1 Reply Last reply Jun 18, 2022, 6:19 PM Reply Quote 1
      • A
        AliMirzaei5778 @PeterJones
        last edited by Jun 18, 2022, 6:19 PM

        @peterjones
        Thank you very much. Everything is perfect.

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