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?
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
add a comment |
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
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
add a comment |
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
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
elisp text-editing text
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered 2 days ago
TobiasTobias
15.3k11035
15.3k11035
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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