The UNIX and Linux Forums  

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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-18-2007
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
Reply With Quote
Forum Sponsor
  #2  
Old 12-18-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
nawk  '
{
  arr[substr($1, 1, 4)]++
}
END {
  for (i in arr)
    print i, arr[i]
}' myFile
Reply With Quote
  #3  
Old 12-18-2007
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
Reply With Quote
  #4  
Old 12-18-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
given a sample input provided I get:
Code:
1236 2
1235 3
1234 4
Pls provide your exact input data using vB Codes
Reply With Quote
  #5  
Old 12-18-2007
Registered User
 

Join Date: Nov 2007
Posts: 85
Try this one

cut -c1-4 filename|sort|uniq -c
Reply With Quote
  #6  
Old 12-19-2007
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0