- Unix Awk array not printing values
- processbody() {
- nawk '
- NR == FNR {
- split($0, x, "@")
- country_code[x[2]] = x[1]
- next
- system(" echo " I am here ">>/tmp/abc.txt")
- }
- {
- CITIZEN_COUNTRY_NAME = "INDIA"
- system(" echo " I am here 1">>/tmp/abc.txt")
- if (CITIZEN_COUNTRY_NAME in country_code) {
- value = country_code[CITIZEN_COUNTRY_NAME]
- system(" echo " I am here 2">>/tmp/abc.txt")
- } else {
- value = "null"
- system(" echo " I am here 3">>/tmp/abc.txt")
- }
- system(" echo " I am here 4">>/tmp/abc.txt")
- print "found " value " for country name " CITIZEN_COUNTRY_NAME >> "/tmp/standalone.txt"
- } ' /tmp/country_codes.config
- echo "I am here 5" >> /tmp/abc.txt
- }
- # Main program starts here
- echo "I am here 0" >> /tmp/abc.txt
- processbody
- $ cat country_codes.config
- IND@INDIA
- IND@INDIB
- USA@USA
- CAN@CANADA
- processbody()
- {
- awk '
- {
- split($0, x, "@")
- country_code[x[2]] = x[1]
- #next
- }
- END {
- CITIZEN_COUNTRY_NAME = "INDIA"
- if (CITIZEN_COUNTRY_NAME in country_code) {
- value = country_code[CITIZEN_COUNTRY_NAME]
- } else {
- value = "null"
- }
- print "found " value " for country name " CITIZEN_COUNTRY_NAME
- } ' /tmp/country_codes.config
- }
- # Main program starts here
- processbody
- found IND for country name INDIA
- processbody()
- {
- awk -F@ '
- { country_code[$2] = $1 }
- END {
- CITIZEN_COUNTRY_NAME = "INDIA"
- if (CITIZEN_COUNTRY_NAME in country_code) {
- value = country_code[CITIZEN_COUNTRY_NAME]
- } else {
- value = "null"
- }
- print "found " value " for country name " CITIZEN_COUNTRY_NAME
- } ' /tmp/country_codes.config
- }
- # Main program starts here
- processbody
- found IND for country name INDIA
- awk -F@ '/INDIA/ {print "found " $1 " for country name " $2 }' /tmp/country_codes.config
- IND@INDIA
- IND@INDIB
- USA@USA
- CAN@CANADA
- I am from INDIA
- I am from INDIB
- I am from CANADA
- nawk '
- BEGIN {
- while (getline < "/tmp/country_codes.config")
- {
- split($0,x,"@")
- country_code[x[2]] = x[1]
- }
- }
- { print $1,$2,$3,country_code[$4]}
- ' /tmp/input_file
- I am from IND
- I am from IND
- I am from CAN