How to join some lines with desired specifications in notepad++
-
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=25I 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# - -# - -# 74Because I think the code may not be displayed in the desired state, I have also attached the following image.

Could anyone give me some suggestions on how to solve this issue?
Regards,
Ali -
@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:
- 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)
- lines #2-#6 will always start with spaces, and #1 and #7 will not start with spaces
- 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:
- 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
- FIND WHAT:
- 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
- FIND WHAT:
Note: I used
\x20to match or replace a space to make it easy to copy/paste with a space at the end of the regular expression; I used\tin 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 ;-) -
@peterjones
Thank you very much. Everything is perfect.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login