AnnaR
AnnaR

Reputation: 361

Bash - Deleting the same rows in two CSV files

I have two CSV files - nodes.csv and edges.csv - where the columns are tab delimited. I've deleted certain rows in nodes.csv using

awk -F'\t' -i inplace '($3 != "Symbol")' nodes.csv

How do I delete the corresponding rows in edges.csv?

For example, in nodes.csv, I have:

ANR 35755   ParameterType   uint32_t
CYP 35756   Identifier      status
ANR 35757   CFGEntryNode    ENTRY
ANR 35758   CFGExitNode     EXIT
ANR 35759   Symbol          * host
CYP 35760   Symbol          * irq_status_bits
ANR 35761   Symbol          irq_status_bits

And in edges.csv, I have:

35738   35758   FLOWS_TO
35689   35759   USE
35701   35759   USE
35727   35760   USE
35734   35760   USE
35727   35761   USE
35735   35761   USE

I need to delete rows 5,6,7 in nodes.csv because column 3 has the value symbol. How do I remove rows 5,6,7 in edges.csv?

Output: nodes.csv

ANR 35755   ParameterType   uint32_t
CYP 35756   Identifier      status
ANR 35757   CFGEntryNode    ENTRY
ANR 35758   CFGExitNode     EXIT

edges.csv:

35738   35758   FLOWS_TO
35689   35759   USE
35701   35759   USE
35727   35760   USE

Thank you very much!

Upvotes: 3

Views: 63

Answers (1)

Ed Morton
Ed Morton

Reputation: 204498

awk -F'\t' -i inplace 'NR==FNR{if ($3 != "Symbol") a[NR]} FNR in a' nodes.csv edges.csv

Upvotes: 1

Related Questions