bash delete lines in file from other file code example
Example: 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.