이것은 시스템에서 sh lookup.sh
으로 실행하고있는 정확한 코드입니다. nawk
블록 내 세부 정보가 표시되지 않거나 abc.txt
파일에 인쇄되거나 작성되었습니다. I am here 0
및 I am here 1
만 인쇄됩니다. printf
(nawk
)도 작동하지 않습니다. 도와주세요.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]
무엇을하고 싶습니까? –
'/ tmp/abs.txt' 샘플을 필요한 출력과 함께 제공하십시오. 분명히 이것을위한 간단한 awk 해결책이 있습니다. – ripat