這是我在我的系統中運行的確切代碼sh lookup.sh
。我在nawk
塊中看不到任何詳細信息,或者將其寫入文件abc.txt
。只打印I am here 0
和I am here 1
。即使nawk
中的printf
不起作用。請幫忙。Unix Awk陣列不打印值
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
而且我country_codes.config
文件:
$ cat country_codes.config
[email protected]
[email protected]
[email protected]
[email protected]
你想完成什麼? – 2011-06-14 04:00:49
請提供示例'/ tmp/abs.txt'文件以及必需的輸出。這肯定有一個簡單的awk解決方案。 – ripat 2011-06-14 07:20:52