Counting and print from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting and print from file
# 8  
Old 03-14-2016
Hi RudiC
$14 is 41283.WC . While summing why WC is not being considered.
Kindly explain.
# 9  
Old 03-14-2016
As it is always ".WC", it doesn't matter for indexing/summing. It is removed when printing t+0.
This User Gave Thanks to RudiC For This Post:
# 10  
Old 03-14-2016
The +0 casts the string to a number. Most awk versions discard the trailing non-number characters. But there are a few awk versions that return 0.
This User Gave Thanks to MadeInGermany For This Post:
# 11  
Old 03-15-2016
Damn, I added a division by 3 to the output, is there a way to show the results as integer?

As always, thanks for your time! Smilie

Code:
cat Event.log* | awk 'sub(".*SERVICEDOWN-","") && sub("[^0-9].*","") {A[$0]++} END {for (a in A) print a,A[a]/3}' | sort -k2,2rn

Code:
1234 2746.67
41344 366.667
6533 366.667
436140 363.333
3424 309.333
79269 306
97623 260
7636 104.667
231335 103.333

# 12  
Old 03-15-2016
Set the OFMT variable to e.g. "%.f".
# 13  
Old 03-15-2016
Quote:
Originally Posted by RudiC
Set the OFMT variable to e.g. "%.f".
Sorry RudiC, what does it mean? Smilie
# 14  
Old 03-15-2016
Code:
awk '/down$/ {T[$14]++} END {for (t in T) print t+0, T[t]/3}' OFMT="%.f" Event.log*

I'd propose to consult man awk as well.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help of counting no of column of a file

Hi All , I got stuck on the below scenario.If anyone can help me ,that will be really helpful. I have a target hdfs file layout.I need to know the no of column in that file. Target_RECRD_layout { ABC_ID EN NOTNULLABLE, ABC_COUNTRY CHARACTER ENCODING ASCII NOTNULLABLE, ... (5 Replies)
Discussion started by: STCET22
5 Replies

2. Shell Programming and Scripting

Counting lines in a file using awk

I want to count lines of a file using AWK (only) and not in the END part like this awk 'END{print FNR}' because I want to use it. Does anyone know of a way? Thanks a lot. (7 Replies)
Discussion started by: guitarist684
7 Replies

3. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

4. Shell Programming and Scripting

Counting entries in a file

Hi, I have a very large two column log file in the following format: # Epoch Time IP Address 899726401 112.254.1.0 899726401 112.254.1.0 899726402 154.162.38.0 899726402 160.114.12.0 899726402 165.161.7.0 899726403 ... (39 Replies)
Discussion started by: sajal.bhatia
39 Replies

5. Shell Programming and Scripting

Counting characters within a file

Ok say I wanted to count every Y in a data file. Then set Y as my delimiter so that I can separate my file by taking all the contents that occur BEFORE the first Y and store them in a variable so that I may use this content later on in my program. Then I could do the same thing with the next Y's... (5 Replies)
Discussion started by: puttster
5 Replies

6. Programming

Counting the words in a file

Please find the below program. It contains the purpose of the program itself. /* Program : Write a program to count the number of words in a given text file */ /* Date : 12-June-2010 */ # include <stdio.h> # include <stdlib.h> # include <string.h> int main( int argc, char *argv ) {... (6 Replies)
Discussion started by: ramkrix
6 Replies

7. Shell Programming and Scripting

Counting lines in each block file

hello im new here so i want to say hi everybody :) i have to write a script and im newbie :/ i hope that in this forum are many ppl who knows subject :) i have hundrets folders. in each folder is a file name trace.txt. each trace.txt has a lot of tracert's results separates with "-----" it... (6 Replies)
Discussion started by: michael8484
6 Replies

8. Shell Programming and Scripting

Help me in counting records from file

Hi, Please help me in counting the below records(1st field) from samplefile: Expected output: Count Descr ------------------------------------------- 7 Mean manager 14 ... (7 Replies)
Discussion started by: prashant43
7 Replies

9. UNIX for Advanced & Expert Users

searching one pattern in file and also counting

Hi, everybody this is my pattern in a file thomson, nicolas 5-3871 Wong, Fred 4-4123 Jones, Thomas 1-4122 Salazar, Richard 5-2522 first name and last names of people fallowed by Tele. while i am searching for pattern first name begin with 'S'... (8 Replies)
Discussion started by: ksr.test
8 Replies

10. Shell Programming and Scripting

Counting words in a file

I'm trying to figure out a way to count the number of words in the follwing file: cal 2002 > file1 Is there anyway to do this without using wc but instead using the cut command? (1 Reply)
Discussion started by: r0mulus
1 Replies
Login or Register to Ask a Question