I have searched and helped my way up to the moment but now i am stuck. Basically i have a text file like this :
"02/01/2018 08:34:15"|"02/01/2018 08:34:16"|"Completed"|"70000000000006632150"|"Activation"||"22200995102577"|"External System"|"ALFUNC ASBS"|"ASBS Shpk"|"VF Shop Asbs 1_209"|"**580**"|"1600"||"355672079017"||"1600"|"590279"|"588679"|7|101369|102577|-1|200158
"02/01/2018 08:34:03"|"02/01/2018 08:34:04"|"Completed"|"70000000000006632146"|"Activation"||"22200995102577"|"External System"|"ALFUNC ASBS"|"ASBS Shpk"|"VF Shop Asbs 1_209"|"**601**"|"1100"||"355696369862"||"1106"|"591379"|"590279"|7|101369|102577|-1|200158
"02/01/2018 08:33:17"|"02/01/2018 08:33:18"|"Completed"|"70000000000006632123"|"Activation"||"22200995102577"|"External System"|"ALFUNC ASBS"|"ASBS Shpk"|"VF Shop Asbs 1_209"|"**319**"|"1100"||"355694523968"||"1103"|"592479"|"591379"|7|101369|102577|-1|200158
And i want to replace the bolded values with a name matching the code. I have created a lookup file like this
"319"|"AS003"
"601"|"Z 477"
"580"|"Z 478"
"101"|"AS006"
And i am using awk to search the first file , find the respective value from the 2nd , replace it and write everything to a new file. Everything works great for 319 and 101 but not for the others, and i suspect this is due to the space between Z and the code. Below the code i am using :
tail -n +2 file_name | while read line ####used tail _n +2 to exclude header
do
code=$(echo $line | awk -F'|' '{print $12}' FS=\|)
cn=$(awk -v CID=$code '$1==CID {print $2}' FS=\| lookup_file)
echo $line|awk -v CN=$cn 'BEGIN {FS=OFS="|"} {$12=CN} 1' >> test2.txt
done
For the lines with space in the lookup file i recieve this error in the terminal:
awk: code_value"
awk: ^ unterminated string
and it isn't written in the output file
Any suggestion would be welcomed...