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 number of files in a directory finalight Shell Programming and Scripting 5 05-14-2009 07:57 AM
How count number of fields in a record sureshg_sampat Shell Programming and Scripting 5 01-07-2008 06:30 AM
Finding number ranges using grep DKNUCKLES Shell Programming and Scripting 2 11-07-2007 02:30 AM
Count number of files in subdirectories cbeverly UNIX for Dummies Questions & Answers 2 06-02-2005 03:06 PM
Count Number Of Threads in a Process S.P.Prasad High Level Programming 7 01-02-2003 06:04 AM

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 12-18-2007
shirleyeow shirleyeow is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 19
Number count per number ranges

Hi,

I have a question here that need to get advise from all of you. Let say I have a set of data

12347777
12359899
12347677
12360090
12347688
12359979
12359009
12367022
12346677

I need to count the number that appear in each numbering ranges and the output is like below:

Prefix Count
1234 4
1235 3
1236 2

How can I do this by using shell script? What command that I can use? Please advise. Really appreaciate your help. Thank you so much.

Best Regards,
Shirley
  #2 (permalink)  
Old 12-18-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk  '
{
  arr[substr($1, 1, 4)]++
}
END {
  for (i in arr)
    print i, arr[i]
}' myFile
  #3 (permalink)  
Old 12-18-2007
shirleyeow shirleyeow is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 19
Number count per number ranges

Hi vgersh99,

I have tested on the script with test data, but no output is showing. The output file is empty. Tried to modify the script, but still the same.
Please advise.

Thank you so much.

Best Regards,
Shirley
  #4 (permalink)  
Old 12-18-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
given a sample input provided I get:
Code:
1236 2
1235 3
1234 4
Pls provide your exact input data using vB Codes
  #5 (permalink)  
Old 12-18-2007
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
Try this one

cut -c1-4 filename|sort|uniq -c
  #6 (permalink)  
Old 12-19-2007
shirleyeow shirleyeow is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 19
Smile Number count per number ranges

Hi vgersh99 and ranjithpr,

The script is working now and I able to get the output data that I needed.
Thank you so so so much for your helps.

Thank you.

Best Regards,
Shirley
Sponsored Links
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 12:14 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