Desired Matching Key: $4$3$2 from line 01 and $4 from line 07 of File1.txt
Example: In File1.txt $4=5000, $3=68, $2=89 in line 01 and $4=RT0429 or RT0428 or RT0588 in line 07. The matching key in File2.txt is 50006889RT0428
Issue: I am looking to create a match key from File1.txt and match against File2.txt first 14 characters.
File1.txt (input)
01 89 68 5000
02 83 11
04 83 9 02
03 83 00
06 83 00
07 83 11 RT0429
07 83 09 RT0428
07 88 10 RT0588
01 44 73 8800
02 44 73
04 44 73 02
03 44 73
06 44 73
07 44 11 RT0789
File2.txt (input)
50006889RT0428 CCARD /3010 /E /C A87545457 / // ///11 ///
51002387 CCARD /3000 /E /S N054896334IV / // ///11 ///
51002390800666 CCARD /3000 /E /S N0978898IV / // ///11 ///
File3 (Desired Output) Since only the first record from File1.txt has the matching key, the output would have the matching record from File2.txt
50006889RT0428 CCARD /3010 /E /C A87545457 / // ///11 ///
Script I am using
awk '
BEGIN {
OFS="\t"
out = "File3.txt"
err = "File4.txt"
}
NR==FNR && NF {line[$1]=$0; next}
function print_77_99() {
if (key in line)
print "77", line[key] > out
else {
print "99", date > out
printf "%s", lines >> err
}
}
$1 == "01" {
if (FNR > 1) print_77_99()
key = $4 $3 $2
lines = ""
}
{
print > out
lines = lines $0 "\n"
}
END {print_77_99()}
' File2.txt File1.txt