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 of matched pattern occurance palash2k UNIX for Dummies Questions & Answers 3 04-24-2008 03:33 PM
SED Search Pattern and Replace with the Pattern racbern Shell Programming and Scripting 4 03-15-2008 05:59 AM
How to count pattern in column ahjiefreak Shell Programming and Scripting 12 12-04-2007 07:53 PM
count the number chracters occurances in a line skyineyes Shell Programming and Scripting 6 06-26-2007 09:09 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-10-2008
cyber111 cyber111 is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
nawk-how count the number of occurances of a pattern, when don't know the pattern

I've written a script to count the total size of SAN storage LUNs, and also display the LUN sizes.
From server to server, the LUNs sizes differ.
What I want to do is count the occurances as they occur and change.

These are the LUN sizes:
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
49.95
55.96
55.96
49.99
49.99
49.99
49.99
49.99
49.99
49.99
49.99
49.99

The above would produce something like this:
17x49.95, 2x55.96, 9x49.99

2nd example data file
27.96
27.96
27.96
27.96
27.96
27.96
27.96
13.95
2.95
2.95
142.99
142.99
142.99
142.99
142.99
142.99
142.99

produces
7x27.96, 1x13.95, 2x2.95, 7x142.99

I'm trying to find a way to do this with nawk.
  #2 (permalink)  
Old 05-10-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Code:
nawk '{a[$0]++}END{for (i in a) print  a[i] ,i}'

For a fancier output use:

Code:
nawk '{a[$0]++}END{for (i in a) printf "%-2d -> %.2f \n", a[i], i}' file
Output:

Code:
17 -> 49.95 
9  -> 49.99 
2  -> 55.96
  #3 (permalink)  
Old 05-11-2008
cyber111 cyber111 is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
Thanks very much, that worked well. Very compact!
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 08:57 AM.


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