Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Within the first afternoon I found 2 of the 3 needed solutions, and the 3rd came to me over the weekend!..."

Geography

Where in the world do Tek-Tips members come from?
arrals (TechnicalUser)
4 May 12 5:59
Hi all,
 
i have written this script:
 

Code:
 awk -F';' '
 BEGIN {
 printf "\n"
 printf "\n"
 printf "\n"
 printf "----------------------------------------------\n"
 print " For test "
 printf "----------------------------------------------\n"
 test_200 = 0
 test_300 = 0
 test_500 = 0
 test_1000 = 0
 test_nok = 0
 test_ok = 0
 }
 $5 == 200.0 {test_200++}
 $5 == 300.0 {test_300++}
 $5 == 500.0 {test_500++}
 $5 == 1100.0 {test_1000++}
 $6 !~ /SUCCESS/ {test_nok++}
 $6 ~ /SUCCESS/ {test_ok++}
 {count[$6]++}
 NF>5&&!a[$6,$2]++{e[$6]++}
 END {
 for(j in count) printf "%-30s %-6d\n", j, count[j]
 print ""
 printf "%-30s %-6d\n", "test 200 ", test_200
 printf "%-30s %-6d\n", "test 300 ", test_300
 printf "%-30s %-6d\n", "test 500 ", test_500
 printf "%-30s %-6d\n", "test 1000 ", test_1000
 printf "\n"
 printf "---------------------------------------------------\n"
 printf "%-30s %-6d\n", "test unsuccessful ", test_nok
 printf "%-30s %-6d\n", "test successful ", test_ok
 printf "---------------------------------------------------\n"
 for (i in e) printf "%-30s %-6d\n", i, e[i]
 }
 ' cdr
 in order to process these logs:
 

Code:
 25-04-2012;192.168.70.44;1254545454545110;300.0;SUCCESS
 25-04-2012;192.168.70.31;1254545454545417;500.0;SUCCESS
 30-04-2012;192.168.70.33;e;null;null;General_ERROR_23
 30-04-2012;192.168.70.33;e;null;null;Failure
 30-04-2012;192.168.70.33;e;null;null;Failure
 30-04-2012;192.168.70.33;e;null;null;Failure
 30-04-2012;192.168.70.33;e;null;null;Failure
 30-04-201;192.168.70.34;e;null;null;ERROR_22
 30-04-2012;192.168.70.37;e;null;null;INVALID_NUMBER
 30-04-2012;192.168.70.10;e;null;null;Failure
 30-04-2012;192.168.70.20;1254545454125417;1100.0;SUCCESS
 The script works ok, but i want to format the output.
 
I want the output to be like this(2 tables, with headers and columns):
 


Code:
 *******************************************
 Message name | Number of errors | Numbers of unique IPs
*******************************************
 Failure ----------------5 ------------------2----------
 ERROR_22
 INVALID_NUMBER
 SUCCESS
 
*******************************************
 test_200 | test_300 | test_500 | test_1000
 *******************************************
 0 --------------1---------1------------ 0
 
etc etc....
 I want everything to be formated in some way.
 Maybe my script need also some improvement except formatting...i dont know.
 
Please, take a look at my script, i really need this for my work.
 
Thank you in advance,  
FlorianAwk (Programmer)
8 May 12 15:09
First, your log is dirty. The result can be in the fifth column (SUCCESS) or the sixth column (FAILURE).
Change it and you'll be able to use:

CODE

awk -F";" '{num=0;cmd="grep -c "$6" file.log";cmd|getline num;close(cmd);printf "%-20s %s\n",$6,num}' |sort -u
 
"-F" to change the separator
"6" is the number of the column
"sort -u" will keep only the different lines
"grep -c pattern file" can count the lines containing the pattern.
"printf" and fancier printing are explained here: http://www.staff.science.uu.nl/~oostr102/docs/nawk/nawk_33.html#SEC36

Filtering the lines with 6 columns, before the awk command above, gives:

CODE

ERROR_22             1
Failure              5
General_ERROR_23     1
INVALID_NUMBER       1

Good luck smile

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close