How remove lines which are not equal in two buffers? Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How to insert text after point?Green lines are invisible in diff output for some files in *shell*How to implement remove-key to completely undo the effect of define-keyScheme-like lambda expressions?Can I edit several files synchronously?How remove whitespaces in the beginning of lines?How show (filter) only text lines with all uppercase chars?How to swap strings in all lines?How keep only duplicate lines?How do I delete all blank lines in a buffer?

What is the longest distance a player character can jump in one leap?

Using audio cues to encourage good posture

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?

How to convince students of the implication truth values?

Irreducible of finite Krull dimension implies quasi-compact?

Can a party unilaterally change candidates in preparation for a General election?

How does the math work when buying airline miles?

What would be the ideal power source for a cybernetic eye?

Chinese Seal on silk painting - what does it mean?

Crossing US/Canada Border for less than 24 hours

Why are both D and D# fitting into my E minor key?

また usage in a dictionary

Do I really need to have a message in a novel to appeal to readers?

Most bit efficient text communication method?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Wu formula for manifolds with boundary

Is it cost-effective to upgrade an old-ish Giant Escape R3 commuter bike with entry-level branded parts (wheels, drivetrain)?

Fantasy story; one type of magic grows in power with use, but the more powerful they are, they more they are drawn to travel to their source

Can an alien society believe that their star system is the universe?

Is safe to use va_start macro with this as parameter?

How do pianists reach extremely loud dynamics?

Around usage results

How to answer "Have you ever been terminated?"



How remove lines which are not equal in two buffers?



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How to insert text after point?Green lines are invisible in diff output for some files in *shell*How to implement remove-key to completely undo the effect of define-keyScheme-like lambda expressions?Can I edit several files synchronously?How remove whitespaces in the beginning of lines?How show (filter) only text lines with all uppercase chars?How to swap strings in all lines?How keep only duplicate lines?How do I delete all blank lines in a buffer?










3















Consider the following buffers



buffer_1:



11111111
22222222
33333333
44444444


buffer_2:



55555555
66666666
22222222
44444444


I need to remove all lines which are not equal in buffer_1 and buffer_2.
The resulting buffer_3 must only contain equal lines, i.e.
buffer_3 must be like this



22222222
44444444


The lines which where NOT EQUAL and are removed from buffer_2 are



55555555
66666666


Is it possible in Emacs?










share|improve this question



















  • 2





    comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).

    – D. Ben Knoble
    2 days ago











  • @D.BenKnoble not work for me

    – Alexei
    yesterday















3















Consider the following buffers



buffer_1:



11111111
22222222
33333333
44444444


buffer_2:



55555555
66666666
22222222
44444444


I need to remove all lines which are not equal in buffer_1 and buffer_2.
The resulting buffer_3 must only contain equal lines, i.e.
buffer_3 must be like this



22222222
44444444


The lines which where NOT EQUAL and are removed from buffer_2 are



55555555
66666666


Is it possible in Emacs?










share|improve this question



















  • 2





    comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).

    – D. Ben Knoble
    2 days ago











  • @D.BenKnoble not work for me

    – Alexei
    yesterday













3












3








3


1






Consider the following buffers



buffer_1:



11111111
22222222
33333333
44444444


buffer_2:



55555555
66666666
22222222
44444444


I need to remove all lines which are not equal in buffer_1 and buffer_2.
The resulting buffer_3 must only contain equal lines, i.e.
buffer_3 must be like this



22222222
44444444


The lines which where NOT EQUAL and are removed from buffer_2 are



55555555
66666666


Is it possible in Emacs?










share|improve this question
















Consider the following buffers



buffer_1:



11111111
22222222
33333333
44444444


buffer_2:



55555555
66666666
22222222
44444444


I need to remove all lines which are not equal in buffer_1 and buffer_2.
The resulting buffer_3 must only contain equal lines, i.e.
buffer_3 must be like this



22222222
44444444


The lines which where NOT EQUAL and are removed from buffer_2 are



55555555
66666666


Is it possible in Emacs?







elisp text-editing text






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Lorem Ipsum

1,460515




1,460515










asked 2 days ago









AlexeiAlexei

783212




783212







  • 2





    comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).

    – D. Ben Knoble
    2 days ago











  • @D.BenKnoble not work for me

    – Alexei
    yesterday












  • 2





    comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).

    – D. Ben Knoble
    2 days ago











  • @D.BenKnoble not work for me

    – Alexei
    yesterday







2




2





comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).

– D. Ben Knoble
2 days ago





comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).

– D. Ben Knoble
2 days ago













@D.BenKnoble not work for me

– Alexei
yesterday





@D.BenKnoble not work for me

– Alexei
yesterday










1 Answer
1






active

oldest

votes


















5














In the following I assume that the order of the lines in the result buffer is irrelevant.



For medium size buffers you can use cl-intersection:



(defun txt-intersection (buffer-a buffer-b)
"Only keep the set theoretic intersection of lines in BUFFER-A and BUFFER-B."
(interactive "bBuffer A: nbBuffer B: ")
(with-current-buffer (generate-new-buffer (concat (buffer-name (get-buffer buffer-a))
"∩"
(buffer-name (get-buffer buffer-b))))
(insert
(mapconcat #'identity
(cl-intersection
(split-string
(with-current-buffer buffer-a (buffer-string))
"n")
(split-string
(with-current-buffer buffer-b (buffer-string))
"n")
:test #'string-equal)
"n"))
(display-buffer (current-buffer))))


The second case is the analogous with intersection substituted by set-difference.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "583"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f48939%2fhow-remove-lines-which-are-not-equal-in-two-buffers%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    In the following I assume that the order of the lines in the result buffer is irrelevant.



    For medium size buffers you can use cl-intersection:



    (defun txt-intersection (buffer-a buffer-b)
    "Only keep the set theoretic intersection of lines in BUFFER-A and BUFFER-B."
    (interactive "bBuffer A: nbBuffer B: ")
    (with-current-buffer (generate-new-buffer (concat (buffer-name (get-buffer buffer-a))
    "∩"
    (buffer-name (get-buffer buffer-b))))
    (insert
    (mapconcat #'identity
    (cl-intersection
    (split-string
    (with-current-buffer buffer-a (buffer-string))
    "n")
    (split-string
    (with-current-buffer buffer-b (buffer-string))
    "n")
    :test #'string-equal)
    "n"))
    (display-buffer (current-buffer))))


    The second case is the analogous with intersection substituted by set-difference.






    share|improve this answer



























      5














      In the following I assume that the order of the lines in the result buffer is irrelevant.



      For medium size buffers you can use cl-intersection:



      (defun txt-intersection (buffer-a buffer-b)
      "Only keep the set theoretic intersection of lines in BUFFER-A and BUFFER-B."
      (interactive "bBuffer A: nbBuffer B: ")
      (with-current-buffer (generate-new-buffer (concat (buffer-name (get-buffer buffer-a))
      "∩"
      (buffer-name (get-buffer buffer-b))))
      (insert
      (mapconcat #'identity
      (cl-intersection
      (split-string
      (with-current-buffer buffer-a (buffer-string))
      "n")
      (split-string
      (with-current-buffer buffer-b (buffer-string))
      "n")
      :test #'string-equal)
      "n"))
      (display-buffer (current-buffer))))


      The second case is the analogous with intersection substituted by set-difference.






      share|improve this answer

























        5












        5








        5







        In the following I assume that the order of the lines in the result buffer is irrelevant.



        For medium size buffers you can use cl-intersection:



        (defun txt-intersection (buffer-a buffer-b)
        "Only keep the set theoretic intersection of lines in BUFFER-A and BUFFER-B."
        (interactive "bBuffer A: nbBuffer B: ")
        (with-current-buffer (generate-new-buffer (concat (buffer-name (get-buffer buffer-a))
        "∩"
        (buffer-name (get-buffer buffer-b))))
        (insert
        (mapconcat #'identity
        (cl-intersection
        (split-string
        (with-current-buffer buffer-a (buffer-string))
        "n")
        (split-string
        (with-current-buffer buffer-b (buffer-string))
        "n")
        :test #'string-equal)
        "n"))
        (display-buffer (current-buffer))))


        The second case is the analogous with intersection substituted by set-difference.






        share|improve this answer













        In the following I assume that the order of the lines in the result buffer is irrelevant.



        For medium size buffers you can use cl-intersection:



        (defun txt-intersection (buffer-a buffer-b)
        "Only keep the set theoretic intersection of lines in BUFFER-A and BUFFER-B."
        (interactive "bBuffer A: nbBuffer B: ")
        (with-current-buffer (generate-new-buffer (concat (buffer-name (get-buffer buffer-a))
        "∩"
        (buffer-name (get-buffer buffer-b))))
        (insert
        (mapconcat #'identity
        (cl-intersection
        (split-string
        (with-current-buffer buffer-a (buffer-string))
        "n")
        (split-string
        (with-current-buffer buffer-b (buffer-string))
        "n")
        :test #'string-equal)
        "n"))
        (display-buffer (current-buffer))))


        The second case is the analogous with intersection substituted by set-difference.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        TobiasTobias

        15.3k11035




        15.3k11035



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Emacs Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f48939%2fhow-remove-lines-which-are-not-equal-in-two-buffers%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form