How do I merge two or more consecutive lines into one?



  • hello. I am using v7.1, no update available.

    But, I had an error yesterday morning, something when N++ had to update Plugin Manager and a Npp plugin, don’t remember very well. I will restart the computer tomorow, and I will test again.



  • no, after restart nothing change. And I installed the v.722, ant still doesn’t work. What a bug is this?



  • @guy038 said:

    Click THREE times, on the Replace All button, till the message Replace All: 0 occurrences were replaced is displayed, in blue, at the bottom of the Replace dialog

    Out of curiosity I tried it, and found that I had to press Replace All only TWO times to get a complete replacement on these three groupings of text. The first press of Replace All does the first and third sets of data; the second press does the second set. However, in the end, it changed the data as expected.



  • Hi, Scott, glossar and vasile,

    Yes, Scott, two times are enough, indeed !. However, I replied to glossar for the general case where you do not know, exactly, what is the maximum of lines with “identical beginnings”, because of a huge file, for instance !

    In that case, it’s better to click on the Replace All button till the message 0 occurrences were replaced appears ! Indeed, as long as yon obtain the message Nocccurrences were replaced, with N > 0, you cannot guess that no more occurrence has to be replaced, the next time :-))

    Cheers,

    guy038



  • @Scott-Sumner

    I press 50 times “Replace all”, and nothing happen. There is a bug somewhere…



  • @Frank-Orellana

    this is working fine !



  • hello guy38, and all friends. Maybe you can improve my regex to resolve the solution (other way).

    So, the regex below will bind (merge) all the sentences into one. The problem is that is not cut the words that repeats.

    Search:
    \s+(.*?)

    Replace with:
    leave space



  • there will be another good solution, that works:

    Find What: ^(\w+\s+\w+\s*)(.*)\n\1
    Replace With: \1\2,



  • @guy038 How can I combine a specific line with a character, ei. Line 2 - 7 should be in line 2 only. and same with the others

    e1b28aa3-eac0-459b-b0aa-ca391816e22e-image.png



  • @guy038

    Hello guy,
    I’ve had to re-visit this topic as I encounter a problem with the regex you had provided above, for which I’ve been grateful to you! It’s weird that the said problem accurs when I join two files (with same line structures, i.e. text-tabulation-text order, and with similar contents/texts) that I’m dealing, whereas the regex has so far worked like a charm. What is odd, is that when I apply the regex on the these files individually/separately it still works, only after I join (two of) them it fails. By joining, I mean adding the whole content of a file to the another, sorting it in Excel, pasting back to txt file. The said problem is that it consumes/deletes all texts/contexts/lines except one line (leaving only a comma behind) usually on the second “Replace all” click, so no “0 occurrances were replaced” message is possible.

    What might causes it?

    I use NP++ v. 7.9.3 (64-bit)

    Many thanks in advance!
    glossar



  • Hi, @glossar,

    As usual, could you provide the text ( or part of it ) that you get back from Excel, and saved as text in N++ and for which the regex S/R, below, wrongly removes almost everything ?

    SEARCH (?-s)^((.+\t).+)\R\2(.+)

    REPLACE \1,\x20\3

    BR

    guy038



  • @guy038 said in How do I merge two or more consecutive lines into one?:

    \1,\x20\3

    Hello guy,

    This is what it lefts behind:

    triplex plunger pump	{TECH&ANGEWANDTE} <convey> Dreiplungerpumpe f.; 3-Plunger-Pumpe f.; Triplex-Plungerpumpe f.,
    

    There is a tabulation right after the word “pump”, sorry, I can’t make it visible and there is no CRLF at the en of the line.

    It may be useful or necessary for trouble-shooting to put this line in “context” (as we often use it), so here it is with few lines before and after:

    triplex bundle conductor	{ELEKTROTECH} Bündelleiter m. aus drei Teilleitern, Dreierbündel n.
    triplex chain	{TECH&ANGEWANDTE} <driv> Triplexkette f.
    triplex milling machine	{TECH&ANGEWANDTE} <mach/tool> Dreispindelfräsmaschine f.
    triplex operation	{ELEKTROTECH} NRT Triplexbetrieb m.
    triplex plunger pump	{TECH&ANGEWANDTE} <convey> Dreiplungerpumpe f.; 3-Plunger-Pumpe f.; Triplex-Plungerpumpe f.
    triplex pump	{TECH&ANGEWANDTE} <convey> Dreizylinderpumpe f.; Dreikolbenpumpe f.; 3-Zylinder-Pumpe f advt; Triplexpumpe f.
    triplex ram pump	{TECH&ANGEWANDTE} <convey> Dreiplungerpumpe f.; 3-Plunger-Pumpe f.; Triplex-Plungerpumpe f.
    triple-X syndrome	{MEDIZIN} XXX-Syndrom n., X-Trisomie f. (Chromosomenanomalie)
    triplex system	{TELEKOMM} Triplexsystem n.
    triplex winding	{TECH&ANGEWANDTE} <el> Dreifachwicklung f.; Dreilagenwicklung f.; Dreischleifenwicklung f.
    triplex-coated particle	{TECH} n. NUC TECH dreifach beschichtetes Teilchen nt.
    

    Again, there is a tabulation just before the char “{” on each line, with CRLF at the end.

    And a bit food for trouble-shooting, I’m trying make a “big mama” dictionary file from a series of (smaller) ones, with of course no duplicate headwords, hence applying the regex above. So far I have joined (in the above sense) several of them but there are more to join. Each (new) one of the file I simply add to the already added ones, in a way, I simply glue one after another and on top of another to get the “big mama” after I successfully join all of the files, of course again with no duplicate headwords (=everything before the tabulation is here headword). Suppose, I have three files from which I’d get a “big mama”. I take the first one, sort it in Excel, pasdt back it to txt file, appy the regex, repeat the same process for the second one. Now I simply copy the all content of the second file and paste it to the first one, then I sort it this added content/text in Excel, apply the regex. Now I have a text with no duplicate headwords, but consists the file #1 and #2. The last thing I’d do is to copy the content of the third file, sort it in Excel, past it back to text file, apply the regex to ensure it contains no duplicate headwords before joining it with the already joined file (File1 + File2), coply and past it to this “joined” file, repeat the same process, finally I have the big mama!

    As I said above, the regex works on each separate file, it seems it works as long as the text stays on the same file, but not after transferring one text from one file to another, which at first made me think that it might be with the different encoding issue. But I have checked the encodings of previously successfully joined/added files and verified that encoding doesn’t cause the problem (at least not when one file is UTF-8 and the other is UTF-8-BOM encoded.)

    Now the only thing I could suspect is some char (a non-alphanumeric char or a char that falls beyond coverage of the regex). Since there are thousands of lines in each file, I can’t manually or visually go through to spot them if there is any.

    Sorry for keeping it long this much. Just wanted to give you as much data as possible so that you could trouble-shoot.

    Thanks,
    glossar



  • Hello, @glossar,

    I do not understand. The text that you provided :

    triplex bundle conductor	{ELEKTROTECH} Bündelleiter m. aus drei Teilleitern, Dreierbündel n.
    triplex chain	{TECH&ANGEWANDTE} <driv> Triplexkette f.
    triplex milling machine	{TECH&ANGEWANDTE} <mach/tool> Dreispindelfräsmaschine f.
    triplex operation	{ELEKTROTECH} NRT Triplexbetrieb m.
    triplex plunger pump	{TECH&ANGEWANDTE} <convey> Dreiplungerpumpe f.; 3-Plunger-Pumpe f.; Triplex-Plungerpumpe f.
    triplex pump	{TECH&ANGEWANDTE} <convey> Dreizylinderpumpe f.; Dreikolbenpumpe f.; 3-Zylinder-Pumpe f advt; Triplexpumpe f.
    triplex ram pump	{TECH&ANGEWANDTE} <convey> Dreiplungerpumpe f.; 3-Plunger-Pumpe f.; Triplex-Plungerpumpe f.
    triple-X syndrome	{MEDIZIN} XXX-Syndrom n., X-Trisomie f. (Chromosomenanomalie)
    triplex system	{TELEKOMM} Triplexsystem n.
    triplex winding	{TECH&ANGEWANDTE} <el> Dreifachwicklung f.; Dreilagenwicklung f.; Dreischleifenwicklung f.
    triplex-coated particle	{TECH} n. NUC TECH dreifach beschichtetes Teilchen nt.
    

    seems useless ! Indeed, if I applied the regex S/R, against your example, it does not find any match !

    I need the initial text, which is practically almost removed AFTER processing the regex S/R

    If you prefer, you may send it to me, by e-mail. Here is my temporary e-mail address :

    BR

    guy038



  • Here is my temporary e-mail address

    @glossar

    Do please take advantage of that kindly offered suggestion!



  • @guy038 said in [How do I merge two or more consecutive lines into one?]

    If you prefer, you may send it to me, by e-mail. Here is my temporary e-mail address :

    BR

    guy038

    Just sent it to the above address.

    Thank you!


Log in to reply