Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How count values in awk program based on number of occurance 2

Status
Not open for further replies.

gargamel100

Technical User
Oct 25, 2006
31
CZ
Hi all,

I have some huge file and I want to check it on some values so I wrote script bellow
###################################################################
cat 942prm_$d | tr ' | ' ' ' > prm942_$d.txt # to translate | into empty space
d=`TZ=MET+24 date +%Y%m%d` # date

# And awk rule...

awk ' { if ( ($10==50005) && ($22==128) && ( $12~/^61/) || ($12~/^62/) && length($12) <= 8) print $10; print $12 }' prm942_$d.txt > mobilna.txt

awk ' { if ( ($10==50006) && ($22==128) && ( $12~/^61/) || ($12~/^62/) && length($12) <= 8) print $10; print $12 }' prm942_$d.txt > mobilna.txt

awk ' { if ( ($10==50007) && ($22==128) && ( $12~/^61/) || ($12~/^62/) && length($12) <= 8) print $10; print $12 }' prm942_$d.txt > mobilna.txt
#######################################################################

if colummn $10 is 50005 and $22 is 128 and $12 begins with 61 or 62 and length of that line is not smaller that 8 I need to print colummn $10 and $12 and I made it with above awk comand. Where is colummn $1 represent called number and colummn $12 calee number.
Now I need just small hint ( help ) how count how many times each case occur. I need output like this,

50005---------------4 ( means: the awk rule was ok 4 times for number 50005 )
50006---------------5 ( as above, just five times for number 50006)
50007---------------6 ( as above, just six times for number 50007)

in file mobilna.txt.
In other words how many times some customer which phone number begins with 61 or 62 called number 50005—first awk command, number 50006---second awk command, 50007 --- third awk command and so on.
What I want to say, if rules in awk command

awk ' { if ( ($10==50005) && ($22==128) && ( $12~/^61/) || ($12~/^62/) && length($12) <= 8) print $10; print $12 }' prm942_$d.txt > mobilna.txt

occurs some number of times for number 50005, I need to get output like above. I need to know how many time occurs that. I probably need some kind of counter but I do not know how implement that.
Every help or hint is welcome.
Thanks
 
Out of curiousity try this:

awk ' { if ( ($10==50005) && ($22==128) && ( $12~/^61/) || ($12~/^62/) && length($12) <= 8) print $10; print $12 }' prm942_$d.txt |awk '/50005/END{print "50005 occurs "NR" times"}' > mobilna

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
A starting point:
awk '$10~/^5000[567]$/ && $22==128 && $12~/^6[12]/ && length($12)<=8{++a[$10]}END{for(i in a)print i,a}' prm942_$d.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top