user3692521
user3692521

Reputation: 2641

How to use awk to delete lines of file1 whose column 1 values exist in file2 in Ubuntu?

Say we have file1.csv like this

"agvsad",314
"gregerg",413
"dfwer",53214
"fewf",344

and file2.csv like this

"dfwer"
"fewf"

how to use awk to delete those lines whose column 1 values exist in file2 and get a file3 looks like:

"agvsad",314
"gregerg",413

By the way I am dealing with millions of lines

Upvotes: 0

Views: 95

Answers (2)

Etan Reisner
Etan Reisner

Reputation: 81042

awk 'NR==FNR{seen[$0]++; next} !seen[$1]' file2.csv FS=, file1.csv should do what you want but it will require enough memory to store an entry for each line in file2.csv.

Upvotes: 2

FatalError
FatalError

Reputation: 54621

As an alternative, using grep:

$ grep -vf file2.csv file1.csv 
"agvsad",314
"gregerg",413

Upvotes: 1

Related Questions