Sunday, February 12, 2017

AWK vlookup on Windows in my case

I needed to process two files/sheets to find the matches or mark un-match as Not found or anything similar.
These are extremely long files which causes excel to take forever, or even crash everytime I ran a vlookup between these two sheets.

awk vlookup solution would be something like this
Assuming you have 2 files separated by semicolon as the demiliter.

awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV

If first column of both files are equal, print columns 1 to 8 from the target6.csv file, plus the entire line from source6.csv  if it is not found it will print the value we are looking plus "Not found" and then the entire line from source6.csv


Post a Comment