Hello, @namx3249, @alan-kilborn, @mark-olson, @peterjones, @sky-247 and All,
I found out a general method to reverse the lines of sections, separated with a pure empty line :
Whatever the number of lines of each section
Whatever the number of sections
Let’s go :
We start with the following INPUT text :
01 02 03 04 aaaaa bbbbb ccccc ddddd eeeee fffff ggggg hhhhh iiiii 05 06 07 08 09 10 11 01 02 03 FIRST Line Second line Third line Fourth line Fifth line LAST lineNote the empty line at the very beginning of the data ! ( Important )
With this first regex S/R, we replace any EOL chars, not followed with other EOL chars, with a colon character
SEARCH (?x) \R (?! ^\R )
REPLACE :
We get this temporary text :
:01:02:03:04 :aaaaa:bbbbb:ccccc:ddddd:eeeee:fffff:ggggg:hhhhh:iiiii :05:06 :07:08:09:10:11 :01:02:03 :FIRST Line:Second line:Third line:Fourth line:Fifth line:LAST lineAs you can see :
Any section is rewritten in a single line
Any previous line is simply preceded with a colon character
Any line must end with text without a colon character
Now, with this second regex S/R, we separate each line in two parts :
A first part between the first colon of the line and right before the last colon
A second part from after the last colon till the end of current line
In the replacement phase, we rewrite these two parts, in reverse order, with a leading slash
SEARCH (?x) ( : .+ ) : ( .+ )
REPLACE /\2\1
Click of the Replace All button as many times as the maximum number of lines in sections
Regarding our example, you should click nine times on the Replace All button !
You may also hit the Alt + A shortcut, repeatedly, till the message Replace All: 0 occurrence were replaced... occurs
And we get this temporary text below :
/04/03/02:01 /iiiii/hhhhh/ggggg/fffff/eeeee/ddddd/ccccc/bbbbb:aaaaa /06:05 /11/10/09/08:07 /03/02:01 /LAST line/Fifth line/Fourth line/Third line/Second line:FIRST LineFinally, let’s come back to the normal displaying of your data, with this third regex S/R which simply replaces the colon and slash chracters with a line-break
SEARCH [:/]
REPLACE \r\n
Anc here is your expected OUTPUT text :
04 03 02 01 iiiii hhhhh ggggg fffff eeeee ddddd ccccc bbbbb aaaaa 06 05 11 10 09 08 07 03 02 01 LAST line Fifth line Fourth line Third line Second line FIRST LineNotes :
The trivial cases, of a single data section only or sections of one line only, are correctly handled, too !
Any additional line-breaks, between sections, are preserved in your OUTPUT text
Of course, you can use any char, instead of the colon and the slash characters :
Provided that they cannot be found in your present INPUT data
Provided that you modify the regexes, accordingly
As said above, the second regex S/R needs N successive searches/replacements, where N is the number of lines of the longest section, in your data
BTW, if you redo all the same process, you get the original order of each section !!
Best Regards,
guy038