I have 2 files, one which contains only one column, and another which contains several |-delimited columns. I need to compare file 1 with file 2 and delete common lines, and copy them to a new file.

A "common" line is a line where column 7 of file2 is equal to the (single) value in file1.

  • file1:
  • file2:
  • 1
    how do you want to compare the files? the only connection I can see between them is that 12345 in line 1 of file1 matches 12345 in column 7 of line 2 in file2, and 34890 is in file1 and colum 7 of the third line of file2. Is that what you want to do? compare the lines in file1 with column 7 of file2?
    – cas
    Commented Mar 16, 2023 at 12:02
  • 2
    Welcome to the site. Unfortunately, since your files are completely differently formatted, it is completely unclear what a "common line" between those two might look like. Please edit your post to include (at least) the expected output for your input example. Also, include what you already tried, and where you failed. Otherwise you may get answers that you already know won't work.
    – AdminBee
    Commented Mar 16, 2023 at 12:02
  • yes we need to compare the column 7 in second file with the column in file 1 these 2 are identical Commented Mar 16, 2023 at 16:54

1 Answer 1

$ awk -F'|' 'NR==FNR {a[$1]=1; next}; ! ($7 in a)' file1 file2

This reads in file1, and creates an element in array a for each line. Then it reads in file2, printing any line where column 7 is NOT in array a.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .