title: How to Compare two files using AWK or GREP
body: <p>So I have two questions, I have two files where I am trying to sort and filter. In these two files they each have two columns wherein file1 there is IP and Port and in file2 there is domain and IP.</p>
  
  <pre><code>file1:
  
  Address,Port
  1.2.3.4,8080
  4.5.6.7,80
  6.7.8.9,443
  
  file2:
  
  Domain,IP
  google.com,1.2.3.4
  google.fe,6.7.8.9
  admin.ko,3.2.4.5
  </code></pre>
  
  <p>So the first question: I want to find IPs in file1 that don't match any IP's located in file2.</p>
  
  <p>I have tried using awk, and here is what I used: </p>
  
  <pre><code>awk -F',' FNR==NR{ a[$2]; next } !($1 in a)' file2 file1
  </code></pre>
  
  <p>So I really don't understand awk really well, so could someone also assist me in understanding each section of that awk command you provide :)</p>
  
  <pre><code>Desired output:
  
  Address,Port,Status
  1.2.3.4,8080,Present
  4.5.6.7,80,Not-Present
  6.7.8.9,443,Present
  </code></pre>
  
  <p>The next question, I have no idea how to do it so kindly assist.</p>
  
  <p>Second question: so I want to list the same desired Output as the first one but this time I want to add the domain column.</p>
  
  <pre><code>Desired output:
  
  Address,Port,Domain,Status
  1.2.3.4,8080,google.com,Present
  4.5.6.7,80,NULL,Not-Present
  6.7.8.9,443,google.fe,Present
  </code></pre>
  
  <p>Thank you in advance.</p>