INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

AWK output format

AWK output format

(OP)
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,  

RE: AWK output format

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

Resources

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