Il mio esempio file della tabella assomiglia a quel file Nomeawk dichiarazioni - se non lo trova (grep'ed) fanno
Name1 xxxxx 34
Name1 xxxxx 37
Name2 aaaaa 59
Name2 xxxxx 90
Name4 Name3 12
sembra che
Name1
Name2
Name3
Name4
voglio awk
per abbinare Name1/2/3/4
da file Nome per caricare il file $ 1 e stampare la somma di $ 3. Se Nome non trovato stampa0
- come posso fare tale istruzione if
in awk
?
Quello che ho già fatto:
for i in $(cat Name_file)
do
cat table | awk -v NAME="$i" '($1==NAME) {SUM+=$3} END {print NAME"\t"SUM}'
done
restituisce un valore
Name1 71
Name2 149
Name3
Name4 12
E 'quasi perfetto - voglio aggiungere 0
per Name3
per ottenere
Name1 71
Name2 149
Name3 0
Name4 12
Tanto domanda tale uscita è: Come aggiungere la funzione if not found do
in awk?
mi può suggerire di usare 'invece di' $ (cat file) 'in' $ (
TrueY
Intendi 'per i in $ (
Sì, usa '$ (
TrueY