I have a UNIX script that has nawk block inside it (This is just a part of the UNIX and NAWK script. It has many more logic and the below code should definitely be in nawk) This block that reads a lookup value for Country ISO code from a file that has country and country code values and I face an issue whenever there is a bracket in the country name () or a single apostrope '
Sample values
CIV@COTE D'IVOIRE
COD@CONGO, Democratic Republic of (was Zaire)
Can you pls help me overcome these 2 issues.for a single apostrope can I have it removed from the string or is there any way I can just fine tune the existing code
Code
processbody() {
nawk '{
COUNTRY_NAME = "COTE D'IVOIRE"
if (COUNTRY_NAME != " "){
file = "/tmp/country_codes.txt"
FS = "@"
while( getline < file ) {
if( $0 ~ COUNTRY_NAME ) {
COUNTRY_CODE = $1
}
}
close( file )
}
printf("%s\n",COUNTRY_CODE) > "/tmp/code.txt"
}' /tmp/file.txt
}