Replacing column value in file1 if there's a match from file2

It must be $15=a[$15] not $15=a[$1]

awk 'NR==FNR{a[$1]=$2; next} ($15 in a){$15=a[$15]} 1' FS='|' OFS='|' file2 file1

If you have embedded newlines in quoted fields then try my sed script from

sed '
# Save input in hold buffer
  h
  :Q1
# Substitute an opening "
  s/"//
# If success jump to :Q2
  tQ2
# Restore input; jump to the end (next cycle)
  x; b
  :Q2
# Substitute a closing "
  s/"//
# If success jump to :Q1
  tQ1
# Restore input; jump to the end if last line (having unbalanced quotes)
  x; $b
# Append the next line with a separating space
  N; s/\n/ /
# Save input in hold buffer; jump to :Q1
  h; bQ1
' file1 | awk 'NR==FNR{a[$1]=$2; next} ($15 in a){$15=a[$15]} 1' FS='|' OFS='|' file2 -
1 Like