Need Help to count the deployments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help to count the deployments
# 1  
Old 02-09-2009
Need Help to count the deployments

Hi,
Need help for a script that count no of deployments from the below Sample Input file.

Below is my sample input file. Not sure whether it works or not.
Note: (We can use a seperator if needed)
My output should come like for each Store:

Output should look like:
Store_MS1: 4 Deployments
Store_MS2: 3 Deployments
--MS3
..MS8: 1 Deployment
__________________________________
Sample Input file:
__________________________________



Successfully connected to Admin Server 'Store_Adm' that belongs to domain 'Store_CITY_XXX'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Location changed to serverRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help(domainConfig)

Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help(domainRuntime)

Store_MS1
RxP_01.00.16.00_PT
Security_01.00.16.00_PT
PreEditEngine_01.00.16.00_PT
RxPConfig_01.00.16.00_PT
Store_MS2
Security_01.00.16.00_PT
PreEditEngine_01.00.16.00_PT
RxPConfig_01.00.16.00_PT
Store_MS3
PreEditEngine_01.00.16.00_PT
RxP_01.00.16.00_PT
Store_MS4
PreEditEngine_01.00.16.00_PT
Sore_MS5
PreEditEngine_01.00.16.00_PT
Store_MS6
RxP_01.00.16.00_PT
Store_MS7
PreEditEngine_01.00.16.00_PT
RxP_01.00.16.00_PT
RxPConfig_01.00.16.00_PT
Security_01.00.16.00_PT
Store_MS8
PreEditEngine_RxC_01.00.16.00_PT


Thanks in advance.
# 2  
Old 02-09-2009
Code:
nawk '/Store_.*/ {a[$1]++} END { for(i in a) printf("%s: %d Deployments\n", i, a[i])}' mySampleFile

# 3  
Old 02-09-2009
Not giving me the right output

I run this, but got output as:
Store_MS1: 1 Deployments
Store_MS2: 1 Deployments
Store_MS3: 1 Deployments
Store_MS4: 1 Deployments
Store_MS6: 1 Deployments
Store_MS7: 1 Deployments
Store_MS8: 1 Deployments
.. But it supposed to be 4, 3 etc...
# 4  
Old 02-09-2009
sorry, misunderstood what you wanted - hopefully this is what you wanted:
Code:
nawk '/Store_.*/ {id=$1;next} {a[id]++} END { for(i in a) printf("%s: %d Deployments\n", i, a[i])}' mySampleFile

# 5  
Old 02-09-2009
Try this.

Save the below code in chris2.awk
{

if (substr($1,1,5)=="Store") {

if (NAME!="")
{
printf("%15s:%15s Deployments\n", NAME, COUNT)
}

COUNT=0
NAME=$1

}
else
{
COUNT=COUNT+1

}
}

and if your input file is chris2.txt then run the below command.
awk -f chris2.awk chris2.txt


Thanks,


Chris.
# 6  
Old 02-09-2009
it works

it works.. Thanks for all your quick help.
# 7  
Old 02-09-2009
You may try this
Code:
#!/usr/bin/ksh
i=0;
j=0;
while read Record
do
 if [ ${Record:0:8} == "Store_MS" ]
 then
      if [ $i !=  0 ]
      then
         printf "number of deployments= %d\n" $j
         j=0;
      fi
      i=1;
      printf "%s " $Record;
 elif [ $i == 1 ]
 then
      j=`expr $j + 1`
 fi
done  < input_file
printf "number of deployments= %d\n" $j

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

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

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

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

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

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

7. Emergency UNIX and Linux Support

Package deployments

I have a task to formalize process of our package deployments. We need to create a sprm containing libcurl and a corresponding rpm of srpm. I found that this site has required downloadable packages - Index of /download and should be build for 32 bit architecture applications. Since I am new to this... (8 Replies)
Discussion started by: uunniixx
8 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