Code:
awk '
NR >= 2 {("ls -x *" $3 "*.jpg") | getline L
gsub (/[ ]+/, ",", L)
LB = L
gsub (/0+|.jpg/, "", L)
gsub ($3, $2, L)
$0 = $0 L
split (LB, T1)
n = split (L, T2)
for (; n; n--) OUT = OUT sprintf ("echo mv -- %s %s\n", T1[n], T2[n] ".jpg")
}
1
END {system (OUT)
}
' FS=, file
Full Registration,VIN,Stock ID,Mileage,InternalTrim,Description,Warranty,FranchiseApproved,RegistrationDate,Featured,NewVehicleType,Used stock images
2653BA,WDD1173461N6437866,2795,19434,Leather trim,A Class,Y,Y,19/09/2018,N,CAR,WDD1173461N6437866_1,WDD1173461N6437866_2,WDD1173461N6437866_3
8874MS,WDD1173461N6494217,2745,15452,Leather trim,A Class,Y,Y,19/09/2018,N,CAR,WDD1173461N6494217_1,WDD1173461N6494217_2
mv -- 002795_003.jpg WDD1173461N6437866_3.jpg
mv -- 002795_002.jpg WDD1173461N6437866_2.jpg
mv -- 002795_001.jpg WDD1173461N6437866_1.jpg
mv -- 002745_002.jpg WDD1173461N6494217_2.jpg
mv -- 002745_001.jpg WDD1173461N6494217_1.jpg