bash print lines unique to one file

# Example usage using awk:
awk 'FNR==NR { b[$0] = 1; next } !b[$0]' input_file_1 input_file_2
# This command prints all lines of input_file_2 that aren't found in
#	input_file_1 (i.e. lines that are unique to input_file_2). Another
#	way of saying this is that this removes all lines of input_file_2
#	that are found in input_file_1. 
#	It does this by first adding all unique lines of input_file_1 to an 
#	associative array, which works like a dictionary with a key value
#	pair. Then each line of input_file_2 is compared against the array
#	and if it isn't found in the array, it is printed.

# Note, change $0 to $# if you want to remove lines based on values in
#	specific fields (which don't have to be the same in each file)
# Note, unlike some comm and diff commands, this solution doesn't require
#	the files to be sorted. 

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source