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

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

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?