Insert Mode Help
-
Hello everyone ,
I have been trying to insert content from 2 different xml files into each other .
Here is a part of what I want :
<type name="ACOGOptic"> <lifetime>14400</lifetime> <restock>1800</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="ACOGOptic_6x"> <lifetime>14400</lifetime> <restock>1800</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> <usage name="Police"/> <value name="Tier3"/> <value name="Tier4"/> </type>
This is a part of the original file , I want to paste these in the original file :
<nominal>8</nominal> <min>4</min> <nominal>3</nominal> <min>1</min>
In these 2 empty lines ( this is a part of a 20,000 line file )
I have looked over a few posts but nothing really help because it keeps overwriting the whole thing . Help is appreciated <3
-
Thanks for providing examples in text boxes. That was helpful.
Unfortunately, paste doesn’t work that way – in Notepad++, or any other application I’ve ever used.
-
If it’s literally just those 4 lines that you want to put into your huge file once, then just do it manually. (If necessary, search for the first “blank” line to get your bearings in the huge file. If it’s truly blank, search for
^$
in regular expression mode; if it might have whitespace, then search for^\h*$
in regular expression mode.) -
If it’s those same 4 lines to be inserted, but there are dozens (or hundreds) of groups of two
<type name="AGOGOptic">
then<type name="ACOGOptic_6x">
entries that are spaced exactly like that, then it will be a bit more complicated regular expression, but still doable. If this is what you really want, be very clear about it, and confirm whether it will always beACOGOptic
followed byACOGOptic_6x
, or whether thosename
attributes will be different each time. I ask for the clarification because it will be easier if we can anchor the regular expression to exact phrases, though it’s still doable even if we cannot; but if you don’t explain things explicitly, we’ll come up with a solution for our (mis-)interpretation of your data, then you will come back and say “it doesn’t work”, when really, it was that you didn’t accurately describe your data or desires. -
If it’s really that you have an arbitrary number of non-blank lines in your second file, and you want to stuff those non-blank in order into the blank lines of the first file, then search-and-replace alone isn’t the right tool. It would be a job for a programming language… though if you want to do it live inside Notepad++, one of the scripting plugins will give you access to the files that are open in Notepad++. If this is what you really want, someone might be able to write up an example script for the PythonScript plugin. But I wouldn’t make that effort until you confirm this is exactly what your data is like, and I am sure other regulars would prefer confirmation before writing a script for you, either.
-
If you just want to loop through file#2, and if line#L is non-blank in file#2, then you want to copy it overtop of what’s inside file#1 at line#L no matter what used to be on line#L in file#1: in this case, once again, it’s a programming challenge, not a Notepad++ task, but with a different solution than my third guess in this post; but a script in PythonScript plugin could again implement it. But again, until there’s certainty about what you want, it would likely waste everyone’s time to give a solution,
So once you can be more clear on the edge cases, and the actual algorithm you are trying to follow in your head, I cannot give more than vague assertions that it can be done.
-
-
@peterjones
Thank you for your responseI will provide more clarification unto what I already have given
So , in the original file there are many entries with different names , categories , usage names , quant min and max , and other tags
Here is a longer take from the original file :
Details about second file in the end
<type name="ACOGOptic"> <lifetime>14400</lifetime> <restock>1800</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="ACOGOptic_6x"> <lifetime>14400</lifetime> <restock>1800</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> <usage name="Police"/> <value name="Tier3"/> <value name="Tier4"/> </type> <type name="AK101"> <lifetime>28800</lifetime> <restock>3600</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> <value name="Tier4"/> </type> <type name="AK101_Black"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AK101_Green"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AK74"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> <value name="Tier2"/> <value name="Tier3"/> </type> <type name="AK74_Black"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AK74_Green"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AK74_Hndgrd"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="AK74_WoodBttstck"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="AKM"> <lifetime>28800</lifetime> <restock>3600</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="ContaminatedArea"/> </type> <type name="AKS74U"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="AKS74U_Black"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AKS74U_Bttstck"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="AKS74U_Green"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AK_Bayonet"> <lifetime>28800</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> <value name="Tier2"/> <value name="Tier3"/> </type> <type name="AK_FoldingBttstck"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="AK_FoldingBttstck_Black"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AK_FoldingBttstck_Green"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type> <type name="AK_PlasticBttstck"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/> <category name="weapons"/> <usage name="Military"/> </type> <type name="AK_PlasticBttstck_Black"> <lifetime>14400</lifetime> <restock>0</restock> <quantmin>-1</quantmin> <quantmax>-1</quantmax> <cost>100</cost> <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="1" deloot="0"/> <category name="weapons"/> </type>
And for the second file it is sets of nominal and minimum continuous with the same number of pairs as the number of entries in the original file .
Ofcourse nominals and minimums differ throughoutHere is a longer take from the second one :
<nominal>8</nominal> <min>4</min> <nominal>3</nominal> <min>1</min> <nominal>2</nominal> <min>1</min> <nominal>0</nominal> <min>0</min> <nominal>0</nominal> <min>0</min> <nominal>5</nominal> <min>4</min> <nominal>0</nominal> <min>0</min> <nominal>0</nominal> <min>0</min> <nominal>3</nominal> <min>1</min> <nominal>3</nominal> <min>1</min> <nominal>2</nominal> <min>1</min> <nominal>10</nominal> <min>8</min> <nominal>0</nominal> <min>0</min> <nominal>3</nominal> <min>1</min> <nominal>0</nominal> <min>0</min>
What I want is basically these sets of pairs going into the empty lines in the original file entries . Help would be greatly appreciated as there are many stuff I can do in the future if a solution is made for this .
-
So it’s going to require the PythonScript plugin. If I get a chance later today, I will hack together a solution and post it here when available.
-
@peterjones
Thanks alot , I already have the plug in -
@omar-salamah said in Insert Mode Help:
I already have the plug in
Great. Paste the following into a new script and save it. Make sure that you have FILE1.xml (the destination) in the left/first view, and FILE2.xml (the source) in the right/second view. Then run the script.
(The script is wrapped in a single undo action, so if you run the script and things aren’t right, you should be able to just undo.)
# encoding=utf-8 """in response to https://community.notepad-plus-plus.org/topic/22801/ Put FILE1.xml (the destination) in the left/main view. Put FILE2.xml (the source with the lines to be copied) in the right/second view (View > Move/Clone Current Document > Move to Other View or Right Click on the title and Move to Other View) """ from Npp import editor1,editor2,notepad,MESSAGEBOXFLAGS notepad.messageBox("Ensure that FILE1.xml destination is in view1\nand FILE2.xml source is in view2\nOK if good, CANCEL to stop the script", "Setup Views", MESSAGEBOXFLAGS.OKCANCEL) def processLineInDestination(contents, lineNumber, totalLines): if contents.strip() != "": return 1 srctxt = nextNonblankFromSource() if srctxt == None: return 1 editor1.replaceLine(lineNumber, srctxt) return 1 def nextNonblankFromSource(): myLine = "" while myLine.strip() == "": if nextNonblankFromSource.counter >= editor2.getLineCount(): return None myLine = editor2.getLine(nextNonblankFromSource.counter).rstrip() # don't want newlines to be returned, but want leading spaces to be kept nextNonblankFromSource.counter += 1 return myLine editor1.beginUndoAction() nextNonblankFromSource.counter = 0 editor1.forEachLine(processLineInDestination) editor1.endUndoAction()
(If you could guarantee that line#N in FILE2 would always be on the same line as the blank line#N in FILE1, it could have been done slightly differently, but I wasn’t sure based on your description whether you could always guarantee that, and this version should work under both circumstances.)
-
-
Worked perfectly as intended .
Thank you so much for the effort taken to write the script <3You changin lives
-
Hello, @omar-salamah, @peterjones and All,
Actually, here is your goal :
-
You have a first
File1.xml
file containingN
pure blank lines -
You have a second
File2.xml
file, below, containingM
non-empty lines, withM <= N
<nominal>8</nominal> <min>4</min> <nominal>3</nominal> <min>1</min> <nominal>2</nominal> <min>1</min> <nominal>0</nominal> <min>0</min> <nominal>0</nominal> <min>0</min> <nominal>5</nominal> <min>4</min> <nominal>0</nominal> <min>0</min> <nominal>0</nominal> <min>0</min> <nominal>3</nominal> <min>1</min> <nominal>3</nominal> <min>1</min> <nominal>2</nominal> <min>1</min> <nominal>10</nominal> <min>8</min> <nominal>0</nominal> <min>0</min> <nominal>3</nominal> <min>1</min> <nominal>0</nominal>
And each non-empty line of
File2.xml
must replace the next pure empty line ofFile1.xml
!The @peterjones’s python script, of course, works correctly using the minimal layout of
File2.xml
, tooBest Regards,
guy038
-