|
Re: using arrays [message #220547 is a reply to message #218647] |
Wed, 21 February 2007 03:55 |
KCee
Messages: 16 Registered: October 2006
|
Junior Member |
|
|
#!/bin/ksh
# 2007 Kees D. Hottinga
value=""
valnr=0
echo "third field count"
# Sort the field by the 2nd column.
sort -t\| -k2 test.txt | while read line
do
field2=`echo $line | cut -d'|' -f2`
if [ "$field2" != "$value" ]
then
# New value found.
if [ "$value" != "" ]; then echo "$value $valnr" ; fi
value=$field2
valnr=0
fi
valnr=`expr $valnr + 1`
done
# Last results.
if [ $valnr -gt 0 ] ; then echo "$value $valnr" ; fi
|
|
|