happyv
1
Hi,
PLMN=APPLE
awk ' /is missing/ { flag=1;print > "fruit_output_m1.txt" }
END {
if( flag != 1 )
print "No $PLMN in the store." > "fruit_output_n1.txt"
} ' fruit_result.txt
The output is:
No $PLMN in the store.
Should be:
No APPLE in the store.
Please help!!
aigles
2
The variable is not substitued by the shell because the texte is between simple quotes.
A possible solution :
PLMN=APPLE
awk -v "
/is missing/ {
flag=1;print > \"fruit_output_m1.txt\"
}
END {
if( flag != 1 )
print \"No $PLMN in the store.\" > \"fruit_output_n1.txt\"
}
" fruit_result.txt
Another way:
PLMN=APPLE
awk -v PLMN="$PLMN" '
/is missing/ {
flag=1;print > "fruit_output_m1.txt"
}
END {
if( flag != 1 )
print "No", PLMN, "in the store." > "fruit_output_n1.txt"
}
' fruit_result.txt
Jean-Pierre.