script for taking the stats from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script for taking the stats from a file
# 8  
Old 03-11-2009
this works but how do we pull it for the whole month of february and then the ouput doesntcome for subscriber id's which arenot there thats if a 203 is not in the file it doesnt show for
2 0
144 0

one more thing can we put in an echo statement there like this echo "$i 203's"
# 9  
Old 03-11-2009
Quote:
this works but how do we pull it for the whole month of february and then the ouput doesntcome for subscriber id's which arenot there thats if a 203 is not in the file it doesnt show for
2 0
144 0
You are not very clear explaining what you want. Your original request is to only include lines starting with 203. If you wish get all records irrespective of whether the subscriber has used or not used, then you can do this:

Code:
nawk -F, 'NR==FNR&&$1==203{_[$3]++;next}NF<2{b[$0]++}END{for(i in b){_[i]=="" && _[i]=0; print i,_[i]}}'  datafile subscriber.list

# 10  
Old 03-11-2009
My question was only how do i pull out stats for the whole month.
also it gives the number of 203's only for the subcribers ids which are there in the log file. even if a 203 is not there in the traffic log file for the subscriber id 2 or any other subscriber id it should show a zero.

like for example its doesnt give
2 0
7 0
if there are no 203's.

also can i put an echo statement there.echo "$Y 203's = "

where $Y is the subcriber id

Last edited by archana234; 03-11-2009 at 07:39 PM..
# 11  
Old 03-11-2009
grep ^203 testS | cut -d, -f3 | sort | uniq -c | while read line; do
cnt=$(echo $line | cut -d" " -f1)
acct=$(echo $line | cut -d" " -f2)
echo "Account $acct had $cnt 203's"
done

This is not as elegant as awk but you don't have to keep a list of accounts. You can change the "echo" line to contain your date variables etc..
# 12  
Old 03-11-2009
thanks you testS and where do i put the log file in there.
-rw-r--r-- 1 ins users 203905773 Dec 15 00:00 08121400010202.TLG
-rw-r--r-- 1 ins users 236227823 Dec 16 00:00 08121500010202.TLG
-rw-r--r-- 1 ins users 243940118 Dec 17 00:00 08121600010202.TLG
-rw-r--r-- 1 ins users 237871341 Dec 18 00:00 08121700010202.TLG
-rw-r--r-- 1 ins users 250888222 Dec 19 00:00 08121800010202.TLG
-rw-r--r-- 1 ins users 224493872 Dec 20 00:00 08121900010202.TLG
-rw-r--r-- 1 ins users 218388629 Dec 21 00:00 08122000010202.TLG
-rw-r--r-- 1 ins users 186587338 Dec 22 00:00 08122100010202.TLG
-rw-r--r-- 1 ins users 212704014 Dec 23 00:00 08122200010202.TLG
-rw-r--r-- 1 ins users 223440201 Dec 24 00:00 08122300010202.TLG
-rw-r--r-- 1 ins users 205148228 Dec 25 00:00 08122400010202.TLG
-rw-r--r-- 1 ins users 190723897 Dec 26 00:00 08122500010202.TLG
-rw-r--r-- 1 ins users 196810206 Dec 27 00:00 08122600010202.TLG
-rw-r--r-- 1 ins users 207268885 Dec 28 00:00 08122700010202.TLG
-rw-r--r-- 1 ins users 192394546 Dec 29 00:00 08122800010202.TLG
-rw-r--r-- 1 ins users 213904424 Dec 30 00:00 08122900010202.TLG
-rw-r--r-- 1 ins users 227873419 Dec 31 00:00 08123000010202.TLG
-rw-r--r-- 1 ins users 261625589 Jan 1 00:00 08123100010202.TLG
-rw-r--r-- 1 ins users 930495 Feb 10 10:00 sqlnet.log
-rw-r--r-- 1 ins users 195611078 Feb 11 00:00 09021000010202.TLG
-rw-r--r-- 1 ins users 183961342 Feb 12 00:00 09021100010202.TLG
-rw-r--r-- 1 ins users 195541787 Feb 13 00:00 09021200010202.TLG
-rw-r--r-- 1 ins users 188403819 Feb 14 00:00 09021300010202.TLG
-rw-r--r-- 1 ins users 180083539 Feb 15 00:00 09021400010202.TLG
-rw-r--r-- 1 ins users 174935554 Feb 16 00:00 09021500010202.TLG
-rw-r--r-- 1 ins users 184086392 Feb 17 00:00 09021600010202.TLG
-rw-r--r-- 1 ins users 183132340 Feb 18 00:00 09021700010202.TLG
-rw-r--r-- 1 ins users 204216062 Feb 19 00:00 09021800010202.TLG
-rw-r--r-- 1 ins users 197424799 Feb 20 00:00 09021900010202.TLG
-rw-r--r-- 1 ins users 194341059 Feb 21 00:00 09022000010202.TLG
-rw-r--r-- 1 ins users 184951088 Feb 22 00:00 09022100010202.TLG
-rw-r--r-- 1 ins users 163008982 Feb 23 00:00 09022200010202.TLG
-rw-r--r-- 1 ins users 187907245 Feb 24 00:00 09022300010202.TLG
-rw-r--r-- 1 ins users 210837242 Feb 25 00:00 09022400010202.TLG
-rw-r--r-- 1 ins users 186564560 Feb 26 00:00 09022500010202.TLG
-rw-r--r-- 1 ins users 214959454 Feb 27 00:00 09022600010202.TLG
-rw-r--r-- 1 ins users 209203339 Feb 28 00:00 09022700010202.TLG
-rw-r--r-- 1 ins users 201840157 Mar 1 00:00 09022800010202.TLG
-rw-r--r-- 1 ins users 173722179 Mar 2 00:00 09030100010202.TLG
-rw-r--r-- 1 ins users 221884036 Mar 3 00:00 09030200010202.TLG
-rw-r--r-- 1 ins users 210510974 Mar 4 00:00 09030300010202.TLG

thank u all for helping me out once again as i am not very good at NR and FNR which something very new to me.please bear with me and help me out.
# 13  
Old 03-12-2009
Ok. Suppose you have only these two TLG files for December:

Code:
$ cat 08121500010202.TLG
203,0903100000042C,110,29,3,
207,0903100000042C,670,133,1
207,0903100000052C,36,25,7,0
203,0903100000052C,54,24,3,
203,0903100000052C,36,79,3,0
$
$ cat 08121400010202.TLG
203,0903100000042C,710,29,3,
207,0903100000042C,670,133,1
207,0903100000042C,26,9,7,09
207,0903100000052C,36,25,7,0
203,0903100000052C,720,24,3,
203,0903100000052C,36,79,3,0

Assume this is the subscriber list:
Code:
$ cat subscriber.list
1
2
3
110
218
26
36
42
50
54
670
710
720

Then this is the code & output:
Code:
nawk -F, 'NR==FNR{_[$0]=0;next}$1==203{a[$3]++}END{for(i in _){a[i]==""&&a[i]=0;print i" 203s = "a[i]}}' subs.list 0812*.TLG
2 203s = 0
3 203s = 0
720 203s = 1
26 203s = 0
110 203s = 1
42 203s = 0
710 203s = 1
218 203s = 0
36 203s = 2
50 203s = 0
54 203s = 1
670 203s = 0
1 203s = 0

1. This shows for full month of December (0812*.TLG)
2. This shows count for subscriber which have 203 + those who are NOT in TLG file. No subscriber is missed.
3. It does the echo you wanted.
# 14  
Old 03-12-2009
grep ^203 09022400010202.TLG | cut -d, -f3 | sort | uniq -c | while read line; do
cnt=$(echo $line | cut -d" " -f1)
acct=$(echo $line | cut -d" " -f2)
echo "Account $acct had $cnt 203's"
done

if you want to do each file then wrap it in a for loop
Code:
for file in $(ls `date +%y%m%d0010202.TLG`)
  echo "FILE: $file"
  grep ^203 $file | cut -d, -f3 | sort | uniq -c | while read line; do
    cnt=$(echo $line | cut -d" " -f1)
    acct=$(echo $line | cut -d" " -f2)
    echo "Account $acct had $cnt 203's"
  done
done


Last edited by ldapswandog; 03-18-2009 at 08:16 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute Oracle gather stats via shell script

Hi , I am trying to automate a gather stats in shell script #!/usr/bin/ksh export ORACLE_HOME=/orcl/app/oracle/product/11.2.0.1/db_1 export PATH="$PATH:$ORACLE_HOME/bin" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$ORACLE_HOME/lib32" export TNS_ADMIN=/opt/netprobe/config... (1 Reply)
Discussion started by: neil.k
1 Replies

2. Shell Programming and Scripting

Taking error message from XML file, amending to script

Hello all, I have a question about creating a script that will look for messages on one of our MQ series systems, and fix them. Currently, if we issue a command for example Command.sh errors it gives us: ID:c3e2d840d4f3f3d74040404040404040cb2ef4e62f70f702 <?xml version="1.0"... (3 Replies)
Discussion started by: jeffs42885
3 Replies

3. Shell Programming and Scripting

Script taking more time in CRONTAB

Hello All, I have created a shell script, When i run it manually as ./<script_name> it takes 5 hours to run, but when i am scheduling it in crontab, it is taking 20 hours to run. Please help me and advice, what can be done to reduce the time in crontab. Thank you (6 Replies)
Discussion started by: anand2308
6 Replies

4. Shell Programming and Scripting

Script to load daily average I/O stats from a .ksh file into Oracle db

Hi can anyone help me with a script to load output of the .ksh file into an Oracle database. I have attached sample output of the information that i need to load to the database (2 Replies)
Discussion started by: LucyYani
2 Replies

5. Shell Programming and Scripting

How to ftp multiple files by taking the file name from a input file.

Hi, I'm working on a script which has to copy multiple files from one server to another server. The list of files that are to be copied is present in a file say input.txt. vi input.txt abc.c welcome.c new.c welcome1.c for ftp'ing a single file say 'new.c' the following code... (2 Replies)
Discussion started by: i.srini89
2 Replies

6. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

7. Shell Programming and Scripting

Perl script for taking inputs from one script and storing them into a document.

Hi. I wanted to create a Perl script which can take the outputs of a Perl script as it's input and temporarily store them in a document. Need help. Thanks.:) (8 Replies)
Discussion started by: xtatic
8 Replies

8. Shell Programming and Scripting

script to update the stats

Hi, I am using the below shell script to update the webalizer stats: #!/bin/bash username='elogic1' domain='abcd.com' path_to_webalizer='/hsphere/shared/bin/webalizer' path_to_logs='/hsphere/local/home/elogic1/logs/abcd.com'... (4 Replies)
Discussion started by: gsiva
4 Replies

9. Shell Programming and Scripting

Newbie to perl - Help with stats script

Hi, this is my first post so here goes..... I need help... I am trying to write a script to produce some stats based on a number of searches in a log file. Now i know how to do this using multiple variables which are really just greps, but I want a more efficent way of doing this as my poor... (1 Reply)
Discussion started by: ARwebble
1 Replies

10. Shell Programming and Scripting

script to gather weblogic jvm heap size stats

Hello, has anyone written something that will monitor/gather weblogic heap info ? I need to gather size, high/low stats to a file that I can upload to a speadsheet thanks for your help! (2 Replies)
Discussion started by: galenw
2 Replies
Login or Register to Ask a Question