Re: awk problem converting datafile
- From: Ed Morton <morton@xxxxxxxxxxxxxx>
- Date: Thu, 22 Dec 2005 09:42:32 -0600
Michael Tosch wrote: <snip>
nawk ' / CET / { if (cet++>0) print dat,sum; dat=$3"-"$2"-"$6; sum=0; next } /'"$1"'/ { sum+=$2 } END { if (cet>0) print dat,sum } ' datafile
}
You might want to chage the way you're passing the shell variables value to awk to avoid obscure failures for some settings of "$1". This would be more robust:
nawk -v sel="$1" '
/ CET / { if (cet++>0) print dat,sum; dat=$3"-"$2"-"$6; sum=0; next }
$0 ~ sel { sum+=$2 }
END { if (cet>0) print dat,sum }
' datafile}
See question 24 in the FAQ (http://home.comcast.net/~j.p.h/cus-faq-2.html#24) for details.
Ed. .
- References:
- awk problem converting datafile
- From: krimgelas
- Re: awk problem converting datafile
- From: Michael Tosch
- awk problem converting datafile
- Prev by Date: Re: get the first word of a file
- Next by Date: Re: get the first word of a file
- Previous by thread: Re: awk problem converting datafile
- Next by thread: Re: awk problem converting datafile
- Index(es):
Relevant Pages
|