Q:

vlookup on csv using all 4 columns from file2 to File1 using awk

Trying to do a vlookup on 4 columns on a large dataset of csv file
F1 : File1
TSM,TYPE,NODE,SCHED
AIXTSM1,VHOST,10.199.114.72,DAILY_1800_VM_SDC-CTL-PROD
AIXTSM1,VHOST,ADMET007,DAILY_1800_VM_SDC-CTL-PROD3
AIXTSM2,VHOST,ADMET014,DAILY_1900_VM_UDC-CTL-PROD
AIXTSM1,VHOST,AGGREGATE,DAILY_2200_VM_SDC-CTL-PROD5

F2 
AIXTSM1,VHOST,10.199.114.72,DAILY_1800_VM_SDC-CTL-PROD,YES
AIXTSM1,VHOST,ADMET007,DAILY_1800_VM_SDC-CTL-PROD3,NO
AIXTSM2,VHOST,ADMET014,DAILY_1900_VM_UDC-CTL-PROD,YES
AIXTSM1,VHOST,AGGREGATE4,DAILY_2200_VM_SDC-CTL-PROD5,NA

Desired Result on 17th on F1 : Input File1
TSM,TYPE,NODE,SCHED,2018-11-17
AIXTSM1,VHOST,10.199.114.72,DAILY_1800_VM_SDC-CTL-PROD,YES
AIXTSM1,VHOST,ADMET007,DAILY_1800_VM_SDC-CTL-PROD3,NO
AIXTSM2,VHOST,ADMET014,DAILY_1900_VM_UDC-CTL-PROD,YES
AIXTSM1,VHOST,AGGREGATE,DAILY_2200_VM_SDC-CTL-PROD5,NA

Desired Result after execuring code on 18th F2 : Input File1 
TSM,TYPE,NODE,SCHED,2018-11-17,2018-11-18
AIXTSM1,VHOST,10.199.114.72,DAILY_1800_VM_SDC-CTL-PROD,YES,YES
AIXTSM1,VHOST,ADMET007,DAILY_1800_VM_SDC-CTL-PROD3,NO,NO
AIXTSM2,VHOST,ADMET014,DAILY_1900_VM_UDC-CTL-PROD,YES,YES
AIXTSM1,VHOST,AGGREGATE,DAILY_2200_VM_SDC-CTL-PROD5,NA,NA

Code
awk -F, -v date=$(date +'%Y-%m-%d') ' BEGIN   { OFS = FS } FNR==NR { a[$1] = $5; next } FNR==1  { n1 = n = NF + 1; $n = date; print; next } { $n1 = ($1 in a) ? a[$1] : "NA"; print }' f2 f1 > t && mv -f t f1

Result is not correct with above code 

A:

Looks like your last line shown in your expected output doesn't look to be following your rule shown, could you please try following.
awk -F, -v DAT=$(date +'%Y-%m-%d') '
FNR!=NR && FNR==1{
  print $0","DAT
  next
}
FNR==NR{
  a[$1,$2,$3,$4]=$0
  next
}
{
  $0=(($1,$2,$3,$4) in a)?a[$1,$2,$3,$4]:$0"," $NF ",NA"
}
1
'  Input_file2   Input_file1

Append > temp_file && mv temp_file Input_file in case you want to save output into Input_file itself.

