I want to merge the content of two files but I don't know if it's possible, Please help
darklinkpower last edited by
I have two files that differ in content and I want to make a third one that combines both but I don’t know if it’s possible. The lines look something like this:
sametext <text><![line a[line b, line c, line d, A1, A2, A3]]></text> sametext
sametext <text><![line a[line b, line c, line d, B1, B2, B3]]></text> sametext
And I want to make a third file that looks like this:
sametext <text><![line a[line b, line c, line d, A1, A2, A3, B1, B2, B3]]></text> sametext
Forgive me if this is an easy task but sadly I don’t have the knowledge to do it so I figured I could ask here if it’s possible. Thanks in advance.
darklinkpower last edited by darklinkpower
Said text files contain hundreds of lines like this so doing it manually would be very difficult, that’s why I’m looking if there can be a way to do it with n++. I also forgot to add that the lines differ slightly, changing the content of the different line
<text><![line a[word, ads, wdwd , wsws, dfdf, dff]]></text>
For the next line, while it follows the same structure, changes in the content after “line a[” but end in the same "]]></text> ". So basically what I want is a way to fuse the differences together of the lines that differ but I don’t know if it’s possible since there’s not a clear pattern other than the estructure of the lines
rinku singh last edited by rinku singh
after do as given suggest
PeterJones last edited by
This sounds very similar to the recent “How to merge” topic. You may be able to use or modify-for-use the regex solution solution that @guy038 posted or the PythonScript solution that I posted. They may have to be tweaked slightly for your exact circumstances, but they are a good starting point.
If you get stuck while trying to modify them to meet your needs, let us know what you’ve tried, and what parts are giving you difficulty, and we may be able to help you get unstuck.
darklinkpower last edited by
thanks for the help guys
@gurikbal-singh nice idea, I didn’t know you could select multiple lines that way. Please correct me if I’m wrong but this could only work if the line lenghts are in the same place right? because if the text that I want to copy don’t align then I will copy text that I don’t want to
@PeterJones I don’t think it’s the same issue. There he has 2 list that he wants to merge, without any extra data that he wants to get rid of. What I want to do is just copy some data of the second file, not all.
After googling around I found what you can use expressions to match text and I came up with this that matches the text I want to copy to the other file, but I don’t know how to copy it to the other file. The files are xml files
Here’s what I could come with:
PeterJones last edited by PeterJones
I don’t think it’s the same issue.
I didn’t say it was the same. I said it sounds similar. Good job on coming up with a regex that gets you partway there.
The problem you see now is that it looks like more of a problem than a simple regex will solve. (That said, @guy038 can work magic with his regex and multi-step regex.)
I had meant for the script linked in the other topic to give you a starting point, because I had thought I’d used just normal line-by-line reading in one and writing in the other. But since it wants to merge every line in the second onto N copies of every line in the first, I used some tricks, which eliminated the logic which would have helped you; sorry.
Off the top of my head, the top-level description would be “for each of the matches in the second file (and PythonScript has access to a similar regular expression library, so finding those matches won’t be too difficult), grab the right portion of the matching text, and insert it into the correct line of the first file.” Implementing that in more detail is what programmers get paid for. For some problems, one of us in the Community occasionally writes the script for free (usually if we’re interested in the problem or see that we can apply it generally to a task that we have to do as well, or if it looks like we could get it in a brief amount of time), but that doesn’t always happen (this isn’t a we-guarantee-we’ll-write-your-code-for-free forum, after all). And this one looks to me to be a longer problem than I’m likely to have time for in the forseeable future. Maybe it’ll catch someone else’s eye, though.
if you were to come up with a rough attempt of a PythonScript solution, that got close but not exactly what you wanted, and posted it here, there might be more people who would have the time to help point you in the right direction, or show you what Notepad+±specific features of PythonScript that could help.
Sorry that I don’t offer more of a solution, but while Notepad++ is powerful, there are some things that are better handled with actual programming, and you may have hit one (unless @guy038 proves me wrong).
guy038 last edited by guy038
I was away from the N++ community, since more than a month ( see my post below )
So, @darklinkpower, my reply is quite out of date. But if you still look for a regex solution I can take up the challenge of performing this S/R with regexes !
However you must give me a real example of your
2( short ) files
B, as well as the expected real output file, from these
Simply, as your files are
XMLones, in your future post, write your code in blocks, like below :
Just to give you an idea, of the regexes’s powerful, let’s suppose the input text, below :
<text><![line a[line b, line c, line d, A1, A2, A3]]></text> <text><![line a[line b, line c, line d, B1, B2, B3]]></text> <text><![line a[line b, line c, line d, line e, line f, line g, line h, C1, C2, C3, C4]]></text> <text><![line a[line b, line c, line d, line e, line f, line g, line h, D1, D2, D3, D4]]></text> <text><![line a[Small test, E1, E2, E3, E4, E5, E6, E7, E8, E9]]></text> <text><![line a[Small test, F1, F2, F3, F4, F5, F6, F7, F8, F9]]></text> <text><![line a[word 1, G1, G2]]></text> <text><![line a[word 1, H1, H2]]></text> <text><![line a[I1]]></text> <text><![line a[J1]]></text>
Then, the following regex S/R :
will change, when you click on the
Replace Allbutton, in one go, the text as below :
<text><![line a[line b, line c, line d, A1, A2, A3, B1, B2, B3]]></text> <text><![line a[line b, line c, line d, line e, line f, line g, line h, C1, C2, C3, C4, D1, D2, D3, D4]]></text> <text><![line a[Small test, E1, E2, E3, E4, E5, E6, E7, E8, E9, F1, F2, F3, F4, F5, F6, F7, F8, F9]]></text> <text><![line a[word 1, G1, G2, H1, H2]]></text> <text><![line a[I1, J1]]></text>
As you can see, this regex S/R is able to differentiate the first common part of two consecutive lines from the second variable part which must be merged in one line only ;-))
So, see you later !