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?What options are there for writing better non-programming text in Emacs?Green lines are invisible in diff output for some files in *shell*Make evil-mode more lisp friendly?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 a quick way to find the reverse complement in bash
How remove lines which are not equal in two buffers?
Antler Helmet: Can it work?
What happens to sewage if there is no river near by?
How to motivate offshore teams and trust them to deliver?
Tic tac toe game in a web browser
Right-skewed distribution with mean equals to mode?
Are variable time comparisons always a security risk in cryptography code?
Bold symbols in LuaLaTeX with setmathfont
Did the new image of black hole confirm the general theory of relativity?
Are my PIs rude or am I just being too sensitive?
Regex in IF condition in awk
Black holes as heat sinks
Date formating in QGIS expression
How discoverable are IPv6 addresses and AAAA names by potential attackers?
Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?
What is the longest distance a 13th level monk can jump while attacking on the same turn?
Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?
Why is "Consequences inflicted." not a sentence?
Find longest string in Datatable column
How is the internal pullup resistor in a microcontroller wired?
Should I call the interviewer directly, if HR aren't responding?
Single word antonym of "flightless"
Left action of a group on permutation representation
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?What options are there for writing better non-programming text in Emacs?Green lines are invisible in diff output for some files in *shell*Make evil-mode more lisp friendly?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?
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?
text-editing text
1
comm -12 <(sort file1) <(sort file2)should work too (see this SO question: stackoverflow.com/q/2696055).
– D. Ben Knoble
1 hour ago
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?
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?
text-editing text
text-editing text
edited 2 hours ago
andrej
742413
742413
asked 5 hours ago
AlexeiAlexei
778212
778212
1
comm -12 <(sort file1) <(sort file2)should work too (see this SO question: stackoverflow.com/q/2696055).
– D. Ben Knoble
1 hour ago
add a comment |
1
comm -12 <(sort file1) <(sort file2)should work too (see this SO question: stackoverflow.com/q/2696055).
– D. Ben Knoble
1 hour ago
1
1
comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).– D. Ben Knoble
1 hour ago
comm -12 <(sort file1) <(sort file2) should work too (see this SO question: stackoverflow.com/q/2696055).– D. Ben Knoble
1 hour ago
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 4 hours ago
TobiasTobias
15.1k11035
15.1k11035
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
1
comm -12 <(sort file1) <(sort file2)should work too (see this SO question: stackoverflow.com/q/2696055).– D. Ben Knoble
1 hour ago