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!
  • Students Click Here

*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.

Students Click Here


AWK output format

AWK output format

AWK output format

Hi all,
i have written this script:

 awk -F';' '
 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++}
 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:

 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):

 Message name | Number of errors | Numbers of unique IPs
 Failure ----------------5 ------------------2----------
 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:


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:


ERROR_22             1
Failure              5
General_ERROR_23     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!

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