bash remove common lines from two files2019 Community Moderator Electioncomm not working to find unique words to file1 from two filesHow to remove blank lines from a file in shell?Compare two files and print unmatched linesfind common lines between multiple filesOutput different lines when comparing two filesHow can I remove lines under a sub heading in a file using linux commandsCompare a certain lines from multiple documentsMerge two files: two lines, partial line, two lines, partial line, etcHow to compare multiple files and display the common lines?Linux Compare two files on different field and print field 1 of first file
Friend wants my recommendation but I don't want to
Is there any common country to visit for uk and schengen visa?
What is the tangent at a sharp point on a curve?
UK Tourist Visa- Enquiry
How can I query the supported timezones in Apex?
Did Nintendo change its mind about 68000 SNES?
What is it called when someone votes for an option that's not their first choice?
How are passwords stolen from companies if they only store hashes?
What is the difference between something being completely legal and being completely decriminalized?
How to test the sharpness of a knife?
Do I need to convey a moral for each of my blog post?
Why do I have a large white artefact on the rendered image?
Pre-Employment Background Check With Consent For Future Checks
Do people actually use the word "kaputt" in conversation?
Would mining huge amounts of resources on the Moon change its orbit?
Is VPN a layer 3 concept?
Do I need an EFI partition for each 18.04 ubuntu I have on my HD?
Can "few" be used as a subject? If so, what is the rule?
Why is indicated airspeed rather than ground speed used during the takeoff roll?
Would storms on an ocean world harm the marine life?
Exit shell with shortcut (not typing exit) that closes session properly
Animating wave motion in water
Why I don't get the wanted width of tcbox?
How do researchers send unsolicited emails asking for feedback on their works?
bash remove common lines from two files
2019 Community Moderator Electioncomm not working to find unique words to file1 from two filesHow to remove blank lines from a file in shell?Compare two files and print unmatched linesfind common lines between multiple filesOutput different lines when comparing two filesHow can I remove lines under a sub heading in a file using linux commandsCompare a certain lines from multiple documentsMerge two files: two lines, partial line, two lines, partial line, etcHow to compare multiple files and display the common lines?Linux Compare two files on different field and print field 1 of first file
I have two files, (no blank lines/Spaces/Tabs)
/tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
/tmp/required
SearchText.json
and the end output I want is : (all uncommon lines from /tmp/all)
aa
bb
cc
hello
xyz.txt
I have tried below commands :-
# comm -23 /tmp/required /tmp/all
SearchText.json
# comm -23 /tmp/all /tmp/required
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -13 /tmp/all /tmp/required
SearchText.json
# comm -13 /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# grep -vf /tmp/all /tmp/required
# grep -vf /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -23 <(sort /tmp/all) <(sort /tmp/required)
aa
bb
cc
hello
SearchText.json
xyz.txt
text-processing diff comm
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I have two files, (no blank lines/Spaces/Tabs)
/tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
/tmp/required
SearchText.json
and the end output I want is : (all uncommon lines from /tmp/all)
aa
bb
cc
hello
xyz.txt
I have tried below commands :-
# comm -23 /tmp/required /tmp/all
SearchText.json
# comm -23 /tmp/all /tmp/required
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -13 /tmp/all /tmp/required
SearchText.json
# comm -13 /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# grep -vf /tmp/all /tmp/required
# grep -vf /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -23 <(sort /tmp/all) <(sort /tmp/required)
aa
bb
cc
hello
SearchText.json
xyz.txt
text-processing diff comm
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
while updating the formatting on your post, I noticed some trailing spaces on some of the lines; are there trailing spaces on any lines of your actual files?
– Jeff Schaller
10 hours ago
1
Take a look at the diff command.
– mrflash818
8 hours ago
add a comment |
I have two files, (no blank lines/Spaces/Tabs)
/tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
/tmp/required
SearchText.json
and the end output I want is : (all uncommon lines from /tmp/all)
aa
bb
cc
hello
xyz.txt
I have tried below commands :-
# comm -23 /tmp/required /tmp/all
SearchText.json
# comm -23 /tmp/all /tmp/required
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -13 /tmp/all /tmp/required
SearchText.json
# comm -13 /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# grep -vf /tmp/all /tmp/required
# grep -vf /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -23 <(sort /tmp/all) <(sort /tmp/required)
aa
bb
cc
hello
SearchText.json
xyz.txt
text-processing diff comm
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have two files, (no blank lines/Spaces/Tabs)
/tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
/tmp/required
SearchText.json
and the end output I want is : (all uncommon lines from /tmp/all)
aa
bb
cc
hello
xyz.txt
I have tried below commands :-
# comm -23 /tmp/required /tmp/all
SearchText.json
# comm -23 /tmp/all /tmp/required
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -13 /tmp/all /tmp/required
SearchText.json
# comm -13 /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# grep -vf /tmp/all /tmp/required
# grep -vf /tmp/required /tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
# comm -23 <(sort /tmp/all) <(sort /tmp/required)
aa
bb
cc
hello
SearchText.json
xyz.txt
text-processing diff comm
text-processing diff comm
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 7 hours ago
mrflash818
19917
19917
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 10 hours ago
GirishGirish
112
112
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Girish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
while updating the formatting on your post, I noticed some trailing spaces on some of the lines; are there trailing spaces on any lines of your actual files?
– Jeff Schaller
10 hours ago
1
Take a look at the diff command.
– mrflash818
8 hours ago
add a comment |
while updating the formatting on your post, I noticed some trailing spaces on some of the lines; are there trailing spaces on any lines of your actual files?
– Jeff Schaller
10 hours ago
1
Take a look at the diff command.
– mrflash818
8 hours ago
while updating the formatting on your post, I noticed some trailing spaces on some of the lines; are there trailing spaces on any lines of your actual files?
– Jeff Schaller
10 hours ago
while updating the formatting on your post, I noticed some trailing spaces on some of the lines; are there trailing spaces on any lines of your actual files?
– Jeff Schaller
10 hours ago
1
1
Take a look at the diff command.
– mrflash818
8 hours ago
Take a look at the diff command.
– mrflash818
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
As an alternative to comm, consider grep:
grep -vxFf /tmp/required /tmp/all
This asks for the lines in /tmp/all that do not (-v) exist in the file (-f) /tmp/required. To avoid interpreting any line in /tmp/all as a regular expression, I added the "fixed strings" -F flag. In addition, we want to force the entire line in /tmp/all to match the one(s) from /tmp/required, so we use the -x option.
This method does not require sorted input.
I suspect that your comm -23 <(sort ...) <(sort ...) command would work, if the "SearchText.json" line matched exactly in both files (same amount of trailing spaces, if any).
1
Add-xto thegrepto make it compare complete lines (no substring matches).
– Kusalananda
8 hours ago
good catch; thank you, @Kusalananda!
– Jeff Schaller
8 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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
);
);
Girish is a new contributor. Be nice, and check out our Code of Conduct.
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%2funix.stackexchange.com%2fquestions%2f506980%2fbash-remove-common-lines-from-two-files%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
As an alternative to comm, consider grep:
grep -vxFf /tmp/required /tmp/all
This asks for the lines in /tmp/all that do not (-v) exist in the file (-f) /tmp/required. To avoid interpreting any line in /tmp/all as a regular expression, I added the "fixed strings" -F flag. In addition, we want to force the entire line in /tmp/all to match the one(s) from /tmp/required, so we use the -x option.
This method does not require sorted input.
I suspect that your comm -23 <(sort ...) <(sort ...) command would work, if the "SearchText.json" line matched exactly in both files (same amount of trailing spaces, if any).
1
Add-xto thegrepto make it compare complete lines (no substring matches).
– Kusalananda
8 hours ago
good catch; thank you, @Kusalananda!
– Jeff Schaller
8 hours ago
add a comment |
As an alternative to comm, consider grep:
grep -vxFf /tmp/required /tmp/all
This asks for the lines in /tmp/all that do not (-v) exist in the file (-f) /tmp/required. To avoid interpreting any line in /tmp/all as a regular expression, I added the "fixed strings" -F flag. In addition, we want to force the entire line in /tmp/all to match the one(s) from /tmp/required, so we use the -x option.
This method does not require sorted input.
I suspect that your comm -23 <(sort ...) <(sort ...) command would work, if the "SearchText.json" line matched exactly in both files (same amount of trailing spaces, if any).
1
Add-xto thegrepto make it compare complete lines (no substring matches).
– Kusalananda
8 hours ago
good catch; thank you, @Kusalananda!
– Jeff Schaller
8 hours ago
add a comment |
As an alternative to comm, consider grep:
grep -vxFf /tmp/required /tmp/all
This asks for the lines in /tmp/all that do not (-v) exist in the file (-f) /tmp/required. To avoid interpreting any line in /tmp/all as a regular expression, I added the "fixed strings" -F flag. In addition, we want to force the entire line in /tmp/all to match the one(s) from /tmp/required, so we use the -x option.
This method does not require sorted input.
I suspect that your comm -23 <(sort ...) <(sort ...) command would work, if the "SearchText.json" line matched exactly in both files (same amount of trailing spaces, if any).
As an alternative to comm, consider grep:
grep -vxFf /tmp/required /tmp/all
This asks for the lines in /tmp/all that do not (-v) exist in the file (-f) /tmp/required. To avoid interpreting any line in /tmp/all as a regular expression, I added the "fixed strings" -F flag. In addition, we want to force the entire line in /tmp/all to match the one(s) from /tmp/required, so we use the -x option.
This method does not require sorted input.
I suspect that your comm -23 <(sort ...) <(sort ...) command would work, if the "SearchText.json" line matched exactly in both files (same amount of trailing spaces, if any).
edited 3 hours ago
answered 10 hours ago
Jeff SchallerJeff Schaller
43.5k1161140
43.5k1161140
1
Add-xto thegrepto make it compare complete lines (no substring matches).
– Kusalananda
8 hours ago
good catch; thank you, @Kusalananda!
– Jeff Schaller
8 hours ago
add a comment |
1
Add-xto thegrepto make it compare complete lines (no substring matches).
– Kusalananda
8 hours ago
good catch; thank you, @Kusalananda!
– Jeff Schaller
8 hours ago
1
1
Add
-x to the grep to make it compare complete lines (no substring matches).– Kusalananda
8 hours ago
Add
-x to the grep to make it compare complete lines (no substring matches).– Kusalananda
8 hours ago
good catch; thank you, @Kusalananda!
– Jeff Schaller
8 hours ago
good catch; thank you, @Kusalananda!
– Jeff Schaller
8 hours ago
add a comment |
Girish is a new contributor. Be nice, and check out our Code of Conduct.
Girish is a new contributor. Be nice, and check out our Code of Conduct.
Girish is a new contributor. Be nice, and check out our Code of Conduct.
Girish is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux 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%2funix.stackexchange.com%2fquestions%2f506980%2fbash-remove-common-lines-from-two-files%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
while updating the formatting on your post, I noticed some trailing spaces on some of the lines; are there trailing spaces on any lines of your actual files?
– Jeff Schaller
10 hours ago
1
Take a look at the diff command.
– mrflash818
8 hours ago