need advice on AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need advice on AWK
# 1  
Old 04-14-2008
need advice on AWK

Hallo Guys,

I have an sql script which gives me the output below:

LOGIN_ID ACTION_CODE DATE CASE_REFERENCE FRAUD_TYPE_ID ESTIMATE_LOSS
james_j Assign 17/03/2008 0833003470 High Frequency 77513.92
james_j Assign 17/03/2008 0838117486 High Aggregate Cost of Calls 149830.5
james_j Assign 17/03/2008 0838521885 High Aggregate Cost of Calls 112457.79
james_j Open 17/03/2008 0832880151 High Aggregate Cost of Calls 21445.46
james_j Open 17/03/2008 0832854857 High Aggregate Cost of Calls 39037.13
james_j Open 17/03/2008 0833041781 PD Summary alarm 15537.59
james_j Open 17/03/2008 0832122779 High Aggregate Cost of Calls 17705.54
james_j Open 17/03/2008 0832126015 High Value Calls 16792.49
james_j Open 17/03/2008 0833006332 High Value Calls 26393.33
james_j Open 17/03/2008 0832725833 High Aggregate Cost of Calls 16197.94
james_j Open 17/03/2008 0832127222 High Aggregate Cost of Calls 14136.68
james_j Close 01/04/2008 0832725833 High Aggregate Cost of Calls 16197.94
james_j Close 01/04/2008 0832854857 High Aggregate Cost of Calls 39037.13
james_j Open 01/04/2008 0833041781 PD Summary alarm 15537.59
james_j Open 01/04/2008 0832725833 High Aggregate Cost of Calls 16197.94
james_j Open 01/04/2008 0832854857 High Aggregate Cost of Calls 39037.13

1. First what i wana do is to group all records according to their action code and then add the estimate loss for all records with action code close for example.

Can you please assist.

Regards,
# 2  
Old 04-14-2008
And why don't you use sql for that?
# 3  
Old 04-14-2008
Can someone please give me an answer an not ask me why am i not using SQL?
# 4  
Old 04-14-2008
Something like this?

Code:
awk 'END { for (k in x)
printf "ACTION_CODE: %s\n\n%s\n\nTotal: %60.2f\n\n", 
k, x[k], sum[k] }
NR > 1 { s = $2; $2 = ""
x[s] = x[s] ? x[s]RS$0 : $0; sum[s] += $NF }' file

If not, post an example output.

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 5  
Old 04-17-2008
Bug Help

Hallo Radoulov,

Thank you for the responce. One more question though, If the sql statement outputs to a file called xxx_123.txt THEN how do I run your AWK script?

Regards,
# 6  
Old 04-17-2008
Code:
awk 'END { for (k in x)
printf "ACTION_CODE: %s\n\n%s\n\nTotal: %60.2f\n\n", 
k, x[k], sum[k] }
NR > 1 { s = $2; $2 = ""
x[s] = x[s] ? x[s]RS$0 : $0; sum[s] += $NF }' xxx_123.txt

# 7  
Old 04-17-2008
help

Hi,

Your awk script doesnt give me exactly what I want. Have a look below:

$ cat cm_activities_170408:0302.log
############################ ANALYST REPORT ####################################

LOGIN_ID ACTION_CODE DATE
---------------- ------------------------------ ---------
CASE_REFERENCE FRAUD_TYPE_ID ESTIMATE_LOSS
---------------------------------------------------------------- ------------------------------ -------------
james_j Assign 17-MAR-08
0838521885 High Aggregate Cost of Calls 112457.79

james_j Assign 17-MAR-08
0838117486 High Aggregate Cost of Calls 150801.75

james_j Assign 17-MAR-08
0833003470 High Frequency 77513.92

hyman_c Open 19-MAR-08
0838521885 High Aggregate Cost of Calls 112457.79

hyman_c Open 19-MAR-08
0838521885 High Aggregate Cost of Calls 112457.79

hyman_c Assign 19-MAR-08
0832090883 PD Summary alarm 29401.46

hyman_c Open 01-APR-08
0838521885 High Aggregate Cost of Calls 112457.79

hyman_c Open 07-APR-08
0838521885 High Aggregate Cost of Calls 112457.79

hyman_c Assign 07-APR-08
0734646922 Very Long Duration Call 4

hyman_c Assign 07-APR-08
0833063410 Very Long Duration Call 4261.97

hyman_c Assign 07-APR-08
0782078038 Very Long Duration Call .19

hyman_c Assign 07-APR-08
0730799413 Very Long Duration Call 50.13

hyman_c Open 07-APR-08
0832090883 PD Summary alarm 29401.46

hyman_c Open 07-APR-08
0832090883 PD Summary alarm 29401.46

hyman_c Open 08-APR-08
0734646922 Very Long Duration Call 4

hyman_c Open 08-APR-08
0782078038 Very Long Duration Call .19

hyman_c Open 08-APR-08
0734646922 Very Long Duration Call 4

hyman_c Open 08-APR-08
0782078038 Very Long Duration Call .19

hyman_c Open 08-APR-08
0838521885 High Aggregate Cost of Calls 112457.79

hyman_c Open 08-APR-08
0832090883 PD Summary alarm 29401.46

hyman_c Open 08-APR-08
0782078038 Very Long Duration Call .19

hyman_c Open 09-APR-08
0833063410 Very Long Duration Call 4261.97

hyman_c Open 09-APR-08
0832090883 PD Summary alarm 29401.46

hyman_c Open 09-APR-08
0832090883 PD Summary alarm 29401.46

hyman_c Open 09-APR-08
0734646922 Very Long Duration Call 4

hyman_c Open 09-APR-08
0730799413 Very Long Duration Call 50.13

hyman_c Open 09-APR-08
0838521885 High Aggregate Cost of Calls 112457.79

hyman_c Open 10-APR-08
0833063410 Very Long Duration Call 4261.97

hyman_c Open 10-APR-08
0782078038 Very Long Duration Call .19

hyman_c Open 10-APR-08
0782078038 Very Long Duration Call .19

hyman_c Open 10-APR-08
0734646922 Very Long Duration Call 4

hyman_c Open 10-APR-08
0734646922 Very Long Duration Call 4

hyman_c Open 10-APR-08
0833063410 Very Long Duration Call 4261.97

hyman_c Open 10-APR-08
0730799413 Very Long Duration Call 50.13

hyman_c Open 10-APR-08
0730799413 Very Long Duration Call 50.13

hyman_c Open 11-APR-08
0832090883 PD Summary alarm 29401.46

hyman_c Open 11-APR-08
0734646922 Very Long Duration Call 4

nhlaph_pr Assign 15-APR-08
0832124374 PD Summary alarm 72957.64

$
$ cat test_123.ksh
#!/bin/ksh
set -x
#########################################################################
#
awk 'END { for (k in x)
printf "ACTION_CODE: %s\n\n%s\n\nTotal: %60.2f\n\n",
k, x[k], sum[k] }
NR > 1 { s = $2; $2 = ""
x[s] = x[s] ? x[s]RS$0 : $0; sum[s] += $NF }' /minotaur/Log/stats/cm_activities_170408:0302.log > xxx.log



$ cat xxx.log
ACTION_CODE:


Total: 0.00

ACTION_CODE: ------------------------------

---------------- ---------
---------------------------------------------------------------- -------------

Total: 0.00

ACTION_CODE: Assign

james_j 17-MAR-08
james_j 17-MAR-08
james_j 17-MAR-08
hyman_c 19-MAR-08
hyman_c 07-APR-08
hyman_c 07-APR-08
hyman_c 07-APR-08
hyman_c 07-APR-08
nhlaph_pr 15-APR-08

Total: 113.00

ACTION_CODE: FRAUD_TYPE_ID

CASE_REFERENCE ESTIMATE_LOSS

Total: 0.00

ACTION_CODE: High

0838521885 Aggregate Cost of Calls 112457.79
0838117486 Aggregate Cost of Calls 150801.75
0833003470 Frequency 77513.92
0838521885 Aggregate Cost of Calls 112457.79
0838521885 Aggregate Cost of Calls 112457.79
0838521885 Aggregate Cost of Calls 112457.79
0838521885 Aggregate Cost of Calls 112457.79
0838521885 Aggregate Cost of Calls 112457.79
0838521885 Aggregate Cost of Calls 112457.79

Total: 1015520.20

ACTION_CODE: Open

hyman_c 19-MAR-08
hyman_c 19-MAR-08
hyman_c 01-APR-08
hyman_c 07-APR-08
hyman_c 07-APR-08
hyman_c 07-APR-08
hyman_c 08-APR-08
hyman_c 08-APR-08
hyman_c 08-APR-08
hyman_c 08-APR-08
hyman_c 08-APR-08
hyman_c 08-APR-08
hyman_c 08-APR-08
hyman_c 09-APR-08
hyman_c 09-APR-08
hyman_c 09-APR-08
hyman_c 09-APR-08
hyman_c 09-APR-08
hyman_c 09-APR-08
hyman_c 10-APR-08
hyman_c 10-APR-08
hyman_c 10-APR-08
hyman_c 10-APR-08
hyman_c 10-APR-08
hyman_c 10-APR-08
hyman_c 10-APR-08
hyman_c 10-APR-08
hyman_c 11-APR-08
hyman_c 11-APR-08

Total: 272.00

ACTION_CODE: ACTION_CODE

LOGIN_ID DATE

Total: 0.00

ACTION_CODE: Very

0734646922 Long Duration Call 4
0833063410 Long Duration Call 4261.97
0782078038 Long Duration Call .19
0730799413 Long Duration Call 50.13
0734646922 Long Duration Call 4
0782078038 Long Duration Call .19
0734646922 Long Duration Call 4
0782078038 Long Duration Call .19
0782078038 Long Duration Call .19
0833063410 Long Duration Call 4261.97
0734646922 Long Duration Call 4
0730799413 Long Duration Call 50.13
0833063410 Long Duration Call 4261.97
0782078038 Long Duration Call .19
0782078038 Long Duration Call .19
0734646922 Long Duration Call 4
0734646922 Long Duration Call 4
0833063410 Long Duration Call 4261.97
0730799413 Long Duration Call 50.13
0730799413 Long Duration Call 50.13
0734646922 Long Duration Call 4

Total: 17277.54

ACTION_CODE: PD

0832090883 Summary alarm 29401.46
0832090883 Summary alarm 29401.46
0832090883 Summary alarm 29401.46
0832090883 Summary alarm 29401.46
0832090883 Summary alarm 29401.46
0832090883 Summary alarm 29401.46
0832090883 Summary alarm 29401.46
0832124374 Summary alarm 72957.64

Total: 278767.86

$
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Advice

Guys, Can you tell me what value would additional knowledge of PERL and CGI scripting will add to my skill set of UNIX shell scripting and ORACLE PL/SQL? I understand that PERL is a good tool for text processing. (1 Reply)
Discussion started by: yabhi_22
1 Replies

2. Shell Programming and Scripting

Advice on using awk in ksh with system date

OK I have a simple awk script: $ awk '/03\/11\/10/' foofile|awk -f finderrors.awk I want to use in the ksh script to so that I can do something like this: #!/bin/ksh TODAY=`date +"%D"` awk /$TODAY/ foofile|awk -f finderrors.awk The problem I am having is (I believe) is with the special... (3 Replies)
Discussion started by: bike4life
3 Replies

3. AIX

Need career advice please

Hi all, I'm a Solaris/linux sysadmin with a good general UNIX skills and with a little tiny background on AIX with no exposure to IBM's hardware ( just reading ) , but i think i can cope with it . UNIX jobs nowadays are rare here ( i mean hp-ux , solaris , aix ) not linux specially after the... (6 Replies)
Discussion started by: h@foorsa.biz
6 Replies

4. Shell Programming and Scripting

AWK\SED advice

Hi guys, looking for a little bit of help. I have been given a task to sift through this massive config of events. I need to find out which event is set up for which ID and each entry looks a little like; <test1 CONNECT_TYPE = COPY HOST = USER = PASSWORD =... (1 Reply)
Discussion started by: JayC89
1 Replies

5. Red Hat

Any advice would help

Hi everyone. I must admit up front that I am not very strong when it comes to Linux. I am actually a Windows guy, but don't let that count against me. :) I work for a very small company so we do not have a Server/Linux Admin on staff. Most of our needs have been handled by our WebHost. We have... (2 Replies)
Discussion started by: liquidstyleb
2 Replies

6. UNIX for Dummies Questions & Answers

need advice

i am currently running windows vista home premium, i want to install unix because i just started a computer programing course, i am just wondering if i install unix will i still have vista?? how does it work? will i get a choice of which os to run on system startup?? (1 Reply)
Discussion started by: naner9
1 Replies

7. Shell Programming and Scripting

looking for advice...

Hi. First of all, Im an msoft guy, and when it comes to linux/unix, I'm retarded. Here is what I'm trying to do. I want to start I want to automatically connect to a remote server. Then I need it to login(https) -insert the licensce in the box(vi) -based on that licensce, the... (1 Reply)
Discussion started by: bravo24601
1 Replies

8. Shell Programming and Scripting

first script. need help and advice.

Hello everyone, This is my first post here and this is the first time I am using UNIX OS (Slackware). I find it really useful and powerful and would like to master it but as you may guess I am expreicing quite a few problems. I've been reading a few documentations about it and bash this week... (17 Replies)
Discussion started by: sanchopansa
17 Replies

9. UNIX for Dummies Questions & Answers

Need advice: Awk vs something else?

I have a while read loop cycling through a fixed-length csv file and I'd like to use an if statement to check two fields in each line. I'm basically asking for your suggestions on the best and easiest way to check two fields in each line. I'm sure many of you may be thinking just use awk, but if... (1 Reply)
Discussion started by: yongho
1 Replies

10. UNIX Desktop Questions & Answers

Looking for some advice

I am looking for some advice on wether to use unix or red hat linux? I have played with most windows OS and Mac OS up to in and including OS X. any and all advice would be appreciated (4 Replies)
Discussion started by: justawind
4 Replies
Login or Register to Ask a Question