0

I'm matching 3 columns between a large csv file and a small csv file and writing these to an output file. There are many questions on here that have helped but I can't find the answer to the specific problem I'm running into. When the column entry is shorter, it's not finding the match.

My solution is based on the solution here: compare two columns of different files and print if it matches

The matching columns should be small1 == large120002, small2 == large120003, small3 == large120004.

What I am trying...

awk -F, 'NR==FNR{c[$1,$2,$3]++;next};c[$120002,$120003,$120004] > 0' small.csv large.csv > output.csv

This works, sort of. This excludes those rows where large120002 is an int less than 9 characters in length. (So far values for large120002 are 7-9 characters long).

Ever run into this problem before? If possible I would like to stick with an awk solution.

1
  • Thanks for deleting that comma bro. 6th grade English class I was known for my run-on sentences. Solid edit.
    – Chinntimes
    Commented Apr 24, 2018 at 0:23

1 Answer 1

1

Turned out it was a casting issue, so I added 0 to the columns to make sure both were being treated the same by awk.

With the help of: https://stackoverflow.com/questions/5808971/casting-to-int-in-awk

This wound up working..

awk -F, 'NR==FNR{c[$1+0,$2,$3]++;next};c[$120002+0,$120003,$120004] > 0' small.csv large.csv > output.csv

You must log in to answer this question.

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