The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
count the max by awk halola85 Shell Programming and Scripting 9 12-01-2008 07:44 AM
replaying a record count with another record count er_zeeshan05 Shell Programming and Scripting 2 10-30-2008 12:14 AM
Sorting using count, grep and count sukhpal_78 UNIX for Dummies Questions & Answers 2 06-27-2008 01:13 AM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 08:22 PM
CPU count hshapiro UNIX for Dummies Questions & Answers 2 04-03-2006 02:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2009
amiri2000 amiri2000 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 11
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 (permalink)  
Old 02-09-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
nawk '/Store_.*/ {a[$1]++} END { for(i in a) printf("%s: %d Deployments\n", i, a[i])}' mySampleFile
  #3 (permalink)  
Old 02-09-2009
amiri2000 amiri2000 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 11
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 (permalink)  
Old 02-09-2009
cdlaforc cdlaforc is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
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.
  #5 (permalink)  
Old 02-09-2009
amiri2000 amiri2000 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 11
it works

it works.. Thanks for all your quick help.
  #6 (permalink)  
Old 02-09-2009
tommy1 tommy1 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 16
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
  #7 (permalink)  
Old 02-09-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0