Replace Lines from different files
-
Hello dear community,
I have no past experience in Notepad++
and I would like to ask for your help/instructions.
I have a file to translate and it goes like this:
Original file:GER;10 ;Ja ENG;10 ;Yes ITA;10 ;Sì BGL;10 ; FRC;10 ;Oui NLD;10 ;Ja ESP;10 ;Sí GER;11 ;\nHöhe des Bodens ENG;11 ;\nHeight of bottom panel ITA;11 ;\nAltezza ripiano (distanza da terra) BGL;11 ; FRC;11 ;\nHauteur du fond NLD;11 ;\nHoogte van de bodem ESP;11 ;\nEspesor de la base
translated file:
BGL;10 ;TEXT1 BGL;11 ;TEXT2 BGL;12 ;TEXT3
I want to replace all the lines in the original file
that are matching the beginning of the line in the translated file. -
Notepad++ cannot natively do it in a single step. Either you will have to copy the second file to the end of the first, then do a complicated search-and-replace, or you will have to install the PythonScript Plugin for Notepad++, then populate the script I shared here with the data from your second file, and run the script.
If you choose the search-and-replace technique, you can either wait for someone to chime in with a custom expression, or you can search the forum for “translate” and “regex” or “regular expression”
-
Hello, @alexei-kurakin, @peterjones and All,
As explained by @peterjones, a simple solution using
regular expressions
could be used !However, it depends on the average size of your
original
file. So , what about its size and its number of lines ?I assume that the
translated
file is probably more light compared to theoriginal
one !Note that my future solution could add, simultaneously, the translation of several languages, all at once !
See you later,
Best Regards,
guy038
-
Hi, @guy038
Original file has 550k lines :) (14.6MB)
and it has 30 different languages
my translated file has 17k lines only with translation
of the specific language
can I hear about your solution also? -
Hi, @alexei-kurakin, @peterjones and **All,
Thanks for your additional information. This confirms that a regex solution should be OK !
Just follow all the following steps, carefully !
-
Copy-paste your
original
file in a new file named, lest’s say,output.txt
-
At the end of the
output.txt
file, add a new line with, for instance, severalequal
signs -
Then, right after, add the contents of your
T translated
file
Thus, the new
output.txt
file should contain the temporary text :GER;10 ;Ja ENG;10 ;Yes ITA;10 ;Sì BGL;10 ; FRC;10 ;Oui NLD;10 ;Ja ESP;10 ;Sí GER;11 ;\nHöhe des Bodens ENG;11 ;\nHeight of bottom panel ITA;11 ;\nAltezza ripiano (distanza da terra) BGL;11 ; FRC;11 ;\nHauteur du fond NLD;11 ;\nHoogte van de bodem ESP;11 ;\nEspesor de la base =============================================== BGL;10 ;TEXT1 BGL;11 ;TEXT2 BGL;12 ;TEXT3 BGL;14 ;TEST
-
Move at the very beginning of the
output.txt
file -
Now, open the Replace dilaog (
Ctrl+ H
) -
Uncheck all box options
-
SEARCH
(?x-is) ^ ( .+ ) \h+ ; $ (?= (?s: .+ =+ .+? ) ^ \1 \h+ ; ( .+ ) $ ) | (?s) ^ =+ .+
-
REPLACE
?1$0\2
-
Click once on the
Replace All
button ( or many times on theReplace
dialog )
Here you are !
You get your expected text :
GER;10 ;Ja ENG;10 ;Yes ITA;10 ;Sì BGL;10 ;TEXT1 FRC;10 ;Oui NLD;10 ;Ja ESP;10 ;Sí GER;11 ;\nHöhe des Bodens ENG;11 ;\nHeight of bottom panel ITA;11 ;\nAltezza ripiano (distanza da terra) BGL;11 ;TEXT2 FRC;11 ;\nHauteur du fond NLD;11 ;\nHoogte van de bodem ESP;11 ;\nEspesor de la base
=>
-
All the lines, which ended with a semicolon, are now completed with their translated counterparts
-
The line of
equal
signes and the contents of thetranslated
file, below, have been removed, as well
I also assume that your
translated
file does not contain the “same” line with different translations !For instance :
BGL;10 ;TEXT1 BGL;11 ;TEXT2 BGL;10 ;A SECOND translation BGL;12 ;TEXT3 BGL;11 ;an other text BGL;13 ;TEST BGL;10 ;A THIRD translation
However, don’t worry as this regex always choose the first
tranlated
word found of the list !So, regarding this part of the
tranlated
file, theoriginal
file would contain :BGL;10 ;TEXT1 BGL;11 ;TEXT2 BGL;12 ;TEXT3 BGL;13 ;TEST
Best Regards,
guy038
-
-
Hello, @alexei-kurakin,
I think that I spoke too quickly ! Because I initially thought that your
original
file had a size of550 kb
( not550k
lines ! )So, I’m afraid that my regex method is useless and that you need a scripting solution !
BR
guy038
You may test my regex solution with a smaller
original
and, may be, a smallertranslated
files ! But it should not work for your exact file sizes :-((I did a quick test : with an original file of about
100,000
lines, it will be still OK. But for a file containing500,000
lines, the results are erroneous !