Count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count
# 1  
Old 09-15-2010
Count

Hi All,

i am new to unix scripting,i need a help

Actually i want to take the count of two variables from a file.And i want to write that to another file.

can you please help me in this.
# 2  
Old 09-15-2010
Post sample input and desired output.
# 3  
Old 09-15-2010
INPUT FILE:

ACCOUNT NUMBER TEMPLATE DEL-CHNL TIMESTAMP
==============================================================
0000176576100033551 POSRSPS W 2010-09-08 03:15:04
0000176557100008322 POSNISPS W 2010-09-08 08:46:55
0000176557100025391 POSRRSLS F 2010-09-08 08:54:02
0000176576100033551 POSRSPS F 2010-09-08 09:10:01
0000176557100025045 POSRSPS F 2010-09-08 09:18:56
0000176557100020889 POSNISPS W 2010-09-08 09:20:05
0000176557100025425 POSNISPS W 2010-09-08 09:28:28


Here W and F are two variables

i want to take the count of these

W means pdf
F means pcl

output:

total pdf = w count
total pcl = f count

total = w+f count

Input file is a large file
# 4  
Old 09-15-2010
Code:
awk '{a[$3]++};END{print "total pdf = "a["W"]"\nprint total pcl = "a["F"]"\ntotal = "a["W"]+a["F"]}' file

# 5  
Old 09-15-2010
hi

First of tahnks for your quick repy.

my output is an another file and the format of that is

summary
...............................................................

pdf = w
pcl = f

..........................

total = w + f

---------- Post updated at 02:40 AM ---------- Previous update was at 02:26 AM ----------

hi

Actually we are running a real time application,and data is coming in MQ.
So when ever we get some data in MQ,our engine in unix will be creating output for that
particular file.And we are getting a detail report once the engine is processed.The egine is up for 23.45 hours.But it will come down for 15 min.At that time we want the count of the these two files.So can you please help me in this.
# 6  
Old 09-15-2010
bartus11's code is fine, small adjusts for new look.

Code:
awk '
NR>2{a[$3]++}
END{ 
         print "summary\n..............................................................."
         print "total pdf = "a["W"]"\ntotal pcl = "a["F"]
         print "..........................\ntotal = "a["W"]+a["F"]
       }
' infile  >> outfile

put the command in cronjob ,and run it at engine down time.
# 7  
Old 09-15-2010
hi thanks

but one more this that we are running in sun OS,

all the files is coming in this dir

/dartprod01/glob/logs/exstream/

we are having the detail report with the timestamp
crsd001_vhdcap2m_DETRPT.TXT.091410:031508
crsd001_phdcap2m_DETRPT.TXT.091410:031508

this summary script look in to the following files
and we need to get seperate summary like
crsd001_vhdcap2m_SUMMARY.TXT.091410:031508
crsd001_vhdcap2m_SUMMARY.TXT.091410:031508

you know we are getting detail report when ever data is present in MQ
But we have to look into the last detail report,ie just before 3.15
how we can implement this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. Shell Programming and Scripting

Count the pipes "|" in line and delete line if count greter then number.

Hello, I have been working on Awk/sed one liner which counts the number of occurrences of '|' in pipe separated lines of file and delete the line from files if count exceeds "17". i.e need to get records having exact 17 pipe separated fields(no more or less) currently i have below : awk... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

4. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

5. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

6. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

7. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

8. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

9. UNIX for Dummies Questions & Answers

Sorting using count, grep and count

Hi, I trying to sort information in a file by making count for every object. For example: A B A D A B C i would like to sort out count for each object (A's, B's and etc) but in actual case i dont know the object but i know the position ofthe object. do i need to use array as well? Any... (2 Replies)
Discussion started by: sukhpal_78
2 Replies

10. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies
Login or Register to Ask a Question