Print only what is exclusive to a file compared to another in Bash
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Good day everyone,
I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.
I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.
File A (1111.com,1112.com,www.1113.com,1114.com)
File B (1111.com,1199.com,1299.com,www2.1329.com)
My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.
Does anyone have a solution ?
files diff comm
add a comment |Â
up vote
0
down vote
favorite
Good day everyone,
I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.
I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.
File A (1111.com,1112.com,www.1113.com,1114.com)
File B (1111.com,1199.com,1299.com,www2.1329.com)
My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.
Does anyone have a solution ?
files diff comm
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Good day everyone,
I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.
I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.
File A (1111.com,1112.com,www.1113.com,1114.com)
File B (1111.com,1199.com,1299.com,www2.1329.com)
My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.
Does anyone have a solution ?
files diff comm
Good day everyone,
I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.
I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or not.
File A (1111.com,1112.com,www.1113.com,1114.com)
File B (1111.com,1199.com,1299.com,www2.1329.com)
My goal is to print a file that would print ONLY the hosts that are exclusively in file B. I tried diff and comm but I cannot presort the files, as the entries a sometimes a little bit different.
Does anyone have a solution ?
files diff comm
asked Jul 12 at 12:36
Alistair Wallace
204
204
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
Not being able to presort the files isnâÂÂt a problem:
comm -13 <(sort fileA) <(sort fileB)
This gives
1199.com
1299.com
www2.1329.com
with your examples, assuming each host is on a separate line. -13
tells comm
to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.
I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
â Alistair Wallace
Jul 12 at 12:50
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Not being able to presort the files isnâÂÂt a problem:
comm -13 <(sort fileA) <(sort fileB)
This gives
1199.com
1299.com
www2.1329.com
with your examples, assuming each host is on a separate line. -13
tells comm
to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.
I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
â Alistair Wallace
Jul 12 at 12:50
add a comment |Â
up vote
3
down vote
accepted
Not being able to presort the files isnâÂÂt a problem:
comm -13 <(sort fileA) <(sort fileB)
This gives
1199.com
1299.com
www2.1329.com
with your examples, assuming each host is on a separate line. -13
tells comm
to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.
I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
â Alistair Wallace
Jul 12 at 12:50
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Not being able to presort the files isnâÂÂt a problem:
comm -13 <(sort fileA) <(sort fileB)
This gives
1199.com
1299.com
www2.1329.com
with your examples, assuming each host is on a separate line. -13
tells comm
to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.
Not being able to presort the files isnâÂÂt a problem:
comm -13 <(sort fileA) <(sort fileB)
This gives
1199.com
1299.com
www2.1329.com
with your examples, assuming each host is on a separate line. -13
tells comm
to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines unique to the second file.
answered Jul 12 at 12:42
Stephen Kitt
139k22296359
139k22296359
I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
â Alistair Wallace
Jul 12 at 12:50
add a comment |Â
I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
â Alistair Wallace
Jul 12 at 12:50
I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
â Alistair Wallace
Jul 12 at 12:50
I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much !
â Alistair Wallace
Jul 12 at 12:50
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454886%2fprint-only-what-is-exclusive-to-a-file-compared-to-another-in-bash%23new-answer', 'question_page');
);
Post as a guest
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
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
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