Help to replace a specific text
-
I need to replace the first sentence of each line with a different sentence.
In line 1 you can see that there are two sentences that are the same. The idea is to replace the first sentence with its Spanish translation, and leave the second sentence as it is.This is how it is now:
This is how I want it to look:
Of course we are talking about several hundred lines, so I need to do it in a massive way. I have a text file with all the translated lines, one below the other, and my idea would be to copy and paste these lines and replace them with the first sentences of each line, following the order in which they are presented.
I don’t know if I have explained myself well, if you need me to detail something else I will do it without problems. Thanks.
-
@Parallaxed If the lines are in the same order in the English and translated text files then try a column mode copy/paste. That will give you a file with both English and translated text on the same lines. At that point it should be a trivial regexp to format the lines into your desired layout.
Often when I have a situation like yours I will load the two files into Microsoft Excel as a spreadsheet. Using a spreadsheet gives me more control over safely dealing with hundreds or thousands of lines (which are now spreadsheet rows) while also visually making sure that things match or line up on each row. Once everything looks good in the spreadsheet I can copy/paste the thing into a text file and clean that up into the desired format.
-
So if I understand you have 2 files:
- one that contains the sentences of the first screenshot you posted
- and the other that contains the translated sentences in Spanish.
If the sentences in the first file are in the same order and in the exact same row as in the second, a possible solution could be the use of the plugin Merge files in one that will provide an easy way to join the rows one by one:
row 1 of the 1st file row 1 of the 2nd file
row 2 of the 1st file row 2 of the 2nd file
The plugin will add a separator an alphanumeric string between the two (now joined into one) rows that you can remove with a find and replace operation.
But before that you need the eliminate the sentence you don’t need from the file 1. For doing that you can use find and replace with a regex or column selection to select the first sentence, after you separate it from the second with a long tab (You can set the length of tabulations from Menu > Settings Preferences > Language > Tab Settings > Tab Size) so they get separated and you can use columns selection (Alt+left mouse button click and drag or even with Alt+Shift+Pagedown).But really it would be more intuitive easier to use MS Excel or LibreOffice Calc for doing this type of operation: you can import both files in the software you chose and separates the columns of the first file by
:
and then you can copy and paste the new translated column on the old one so all here comes easy and intuitive. -
Thank you both for responding. I have followed your advice and finally I have been able to do it using Excel, much easier than I imagined. Thanks again!