Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-09-2009
Registered User
 

Join Date: Mar 2009
Posts: 12
script for taking the stats from a file

i have file which contains data like this every day.i need to pull up a report for counting the 203's in that file for each subscriber id.there are around 200 subscriber id's. all ths Y's which i have written in the script are the subscriber id's.could some one give me an idea as to how do it in a better way.

more 09031000010202.TL
203,0903100000042C,710,29,3,
207,0903100000042C,670,133,1
207,0903100000042C,26,9,7,09
207,0903100000042C,42,61,1,0
207,0903100000052C,710,29,7,
207,0903100000052C,50,7,7,09
207,0903100000052C,218,22,1,
207,0903100000052C,36,25,7,0
203,0903100000052C,720,24,3,
203,0903100000052C,36,79,3,0

Script:

#!/bin/sh
set -x
thisday =`date +%y%m%d00010202.TLG`

for Y in 2 144 9 129 16 37 42 45 87 104 53 40 62 63 51 158 18 19 20 21 50 67 82 116 64 100 141 168 170 171 49 84 85 35 34 70 61 69 8 26 27 28 78 79 32 33 10 11 130 25
36 47 57 200 173 6 46 48 55 56 72 118 22 13 110 109 203 29 80 12 660 222 696 664 666 669 670 671 672 674 675 676 677 39 207 208 209 210 211 212 680 681 682 43 683 59 6
84 103 659 205 91 689 690 692 30 215 216 217 218 697 698 700 52 174 705 706 707 220 708 710 711 712 713 714 715 716 717 718 719 720 721 722 23 31 724 219 77 88 17 66 7
30 83 68 120 96 5 667 678 679 685 186 15 726 733 728 731 732 734 221 736 94 95 97 99 41 74 65 105 738 98 38 73 7 4 739 44 740 112 113 114 14 3 1 24 54 81 58;
do
echo "$Y 203's = ";`cat $thisday | grep ^203 | grep "2C,$Y, | wc -l`; done
Sponsored Links
  #2 (permalink)  
Old 03-10-2009
danmero danmero is online now Forum Advisor  
 

Join Date: Nov 2007
Location: H3X
Posts: 1,566
That's complicated , this should work:

Code:
awk -F, 'NR==FNR{_[$0];next}$1==X && $3 in _{a++}END{print a}' X="203" subscriber.list `date +%y%m%d`00010202.TLG

  #3 (permalink)  
Old 03-10-2009
Registered User
 

Join Date: Mar 2009
Posts: 12
should i put this into a subscriber list file

2 144 9 129 16 37 42 45 87 104 53 40 62 63 51 158 18 19 20 21 50 67 82 116 64 100 141 168 170 171 49 84 85 35 34 70 61 69 8 26 27 28 78 79 32 33 10 11 130 25
36 47 57 200 173 6 46 48 55 56 72 118 22 13 110 109 203 29 80 12 660 222 696 664 666 669 670 671 672 674 675 676 677 39 207 208 209 210 211 212 680 681 682 43 683 59 6
84 103 659 205 91 689 690 692 30 215 216 217 218 697 698 700 52 174 705 706 707 220 708 710 711 712 713 714 715 716 717 718 719 720 721 722 23 31 724 219 77 88 17 66 7
30 83 68 120 96 5 667 678 679 685 186 15 726 733 728 731 732 734 221 736 94 95 97 99 41 74 65 105 738 98 38 73 7 4 739 44 740 112 113 114 14 3 1 24 54 81 58
  #4 (permalink)  
Old 03-10-2009
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 250
You should put each subscriber id on a separate line

Code:
2
144
9
etc.

  #5 (permalink)  
Old 03-10-2009
Registered User
 

Join Date: Mar 2009
Posts: 12
ins@ARTMGA01> awk -F, 'NR==FNR{_[$0];next}$1==X && $3 in _{a++}END{print a}' X="203" a.out `date +%y%m%d`00010202.TLG
333868
ins@ARTMGA01>

i get this when i run the above query i am not getting the count of 203's for each subscriber id
  #6 (permalink)  
Old 03-10-2009
Registered User
 

Join Date: Mar 2009
Posts: 12
subscriber id is the list above
  #7 (permalink)  
Old 03-10-2009
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 250

Code:
$ nawk -F, 'NR==FNR{_[$0]=0;next}$1==x && _[$3]!=""{a[$3]++}END{for(i in a){print i,a[i]}}' x=203 subscriber.list `date +%y%m%d`00010202.TLG
720 1
710 1
36 1

Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Taking a particular attribute's value in a file... Llb Shell Programming and Scripting 16 01-07-2009 07:15 AM
script fot taking mount information arunkumar_mca UNIX for Advanced & Expert Users 12 10-21-2008 10:37 AM
put an interactive script in background after taking input epsilonaurigae Shell Programming and Scripting 7 02-15-2008 10:18 PM
script to gather weblogic jvm heap size stats galenw Shell Programming and Scripting 2 02-07-2008 01:34 PM
Shell script is taking more than 3 hrs to execute nvuradi Shell Programming and Scripting 2 11-18-2007 11:02 PM



All times are GMT -4. The time now is 08:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0