I am working on a project in bash script to read three different .csv files and output the similar rows. The three .csv files are formated the same way with the same information but the second column may be different. For example, if I have three csv files, named A.csv, B.csv, and C.csv.
A.csv
Animal, Color, Age
Dog, Brown, 9
Cow, White, 3
Cat, Black, 5
Parrot, Blue, 2
B.csv
Animal, Color, Age
Dog, Black, 9
Cow, White, 3
Cat, Brown, 5
Parrot, Blue, 2
C.csv
Animal, Color, Age
Dog, Brown, 9
Cow, White, 3
Cat, Tan, 5
Parrot, Blue, 2
After running the program, I am looking to get an output like:
Animal, Color, Age
Cow, White, 3
Parrot, Blue 2
I have read up on diff3 but that only outputs the differences which is the opposite of what I am trying to do. Any help would be greatly appreciated. Thanks
Using grep
:
grep A.csv -f B.csv | grep -f C.csv
grep -f FILE
gets the patterns from the FILE.
Output:
Animal, Color, Age
Cow, White, 3
Parrot, Blue, 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With