Move certain texts line
-
Hey, I have a file right here :
> BEGIN STRING HP to the 300 point recovery. > CONTEXT: Items / 1 / description / <UNTRANSLATED > CONTEXT: Items / 30 / description / <UNTRANSLATED > END STRING > BEGIN STRING MP to the 200 point recovery. > CONTEXT: Items / 4 / description / <UNTRANSLATED > END STRING > BEGIN STRING Something over There.... Can you see it ? > CONTEXT: Map014 / events / 87 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map014 / events / 89 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map014 / events / 90 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map014 / events / 91 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map003 / events / 34 / pages / 0/39 / Dialogue <UNTRANSLATED > END STRING
I want to move all the texts above
> Context
to be below it like this :> BEGIN STRING > CONTEXT: Items / 1 / description / <UNTRANSLATED > CONTEXT: Items / 30 / description / <UNTRANSLATED HP to the 300 point recovery. > END STRING > BEGIN STRING > CONTEXT: Items / 4 / description / <UNTRANSLATED MP to the 200 point recovery. > END STRING > BEGIN STRING > CONTEXT: Map014 / events / 87 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map014 / events / 89 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map014 / events / 90 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map014 / events / 91 / pages / 0/89 / Dialogue <UNTRANSLATED > CONTEXT: Map003 / events / 34 / pages / 0/39 / Dialogue <UNTRANSLATED Something over There.... Can you see it ? > END STRING
How do I do that ? please help.
-
@Devin-Rusty
An interesting problem.
As I saw it, we just need to capture the various portions of text (taking into account they may be several lines long), then re-arrange them in a different order.
My solution is what we call a regular expression (regex). That means when using it in the “Replace” function (Ctrl and H keys) you also need the “search mode” as “regular expression” and also have “wrap around” ticked.Find What:
(?-s)(> BEGIN STRING\R)((?:.+\R)+?)((?:> CONTEXT.+\R)+)(\R)
Replace With:\1\4\3\2
In case you’d like to know what the Find expression means we have:
(?-s) means any “.” character in the expression also includes a carriage return/line feed.
(> BEGIN STRING\R) should be self explanatory, it includes “\R” which is the carriage return/line feed.
((?:.+\R)+?) is a bit complicated since we have 2 levels of brackets. The inner ones capture a single line, BUT the “?:” prevents storing that capture UNTIL we have captured as many lines as necessary, the “+?” portion.
((?:> CONTEXT.+\R)+) works similarly to the previous capture, so we cover as many lines as have the “> CONTEXT” in them.
(\R) stops the capturing at the first blank line. The previous capture has the “\R” as well, so two of these together means a blank line.Each of the brackets denotes a capture group (excluding the ones with “?:” following). Each is denoted by the “\1” through “\4”, which we then recreate in a different order.
Give it a go, see how well it works on ALL your data. If you haven’t given a FULL representation of your data there may still be adjustments required. My regex assumes the text before and after (BEGIN and CONTEXT) will always be “CAPITALIZED” and there will always be a “blank line” you wish to insert the text into. As always, I suggest you run it on a copy of your data and check the result before assuming it is 100% effective.
Terry
-
Hi @terry-r, @devin-rusty, and All,
If we assume that there is always, at least ONE pure blank line, between the
CONTEXT:
block of lines and the statement> END STRING
, an other formulation of your regex S/R could be :SEARCH
(?s-i)^(> BEGIN STRING\R)(.+?)(> CONTEXT:.+?\R)(\R)+
REPLACE
\1\4\3\2
Cheers,
guy038
P.S. :
Actually, the syntax
(> CONTEXT:.+?\R)(\R)+
is equivalent to(> CONTEXT:.+?)(\R){2,}
. In other words, it searches for the string> CONTEXT:
followed with the shortest range of any character till, at least, two consecutive line-breaks. But, with the later syntax, the range of characters(> CONTENT:........)
does not include its final line-break !