这是我在我的系统中运行的确切代码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