0

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 ?

0

1 Answer 1

4

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.

1
  • I just tried you solution and it works perfectly ! Much more readable than diff and exactly what I needed, thank you very much ! Commented Jul 12, 2018 at 12:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.