- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find the count
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 07:14 AM
тАО09-27-2004 07:14 AM
I have parsed a number of files for the value on a particular field and stored it in a file. Now I want to know the count of each pattern that is stored in the file. For example, the entries in the file has
abc
abc
abc
def
xyz
xyz
123
123
...
and so on. I want to get the count of the occurance of each values. Say, abc - 3 times, 123 - 5 times etc.
Can anyone please help me
Thanks,
Rahul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 07:18 AM
тАО09-27-2004 07:18 AM
Re: find the count
# grep -c "abc" inputfile
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 07:28 AM
тАО09-27-2004 07:28 AM
Re: find the count
Another way , pipe to wc
grep "abc" somefile |wc
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 07:39 AM
тАО09-27-2004 07:39 AM
Re: find the count
this is easiest way to acheive this.
And if you know pattern, you can do some more things of your linking, like
count=1
cat filename | while read line
echo $line
if [ $line = $pattern ]
((count=count+1))
done
something like above you may like to do.
Hope the above helps
Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 07:42 AM
тАО09-27-2004 07:42 AM
Re: find the count
if the lines are adjacant as in your example, you can also try the uniq command, e.g.
# uniq -c
3 abc
1 def
2 xyz
2 123
regards,
John K.
- Tags:
- uniq
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 08:27 AM
тАО09-27-2004 08:27 AM
Re: find the count
sort file | uniq -c
to get a count for each unique line in file.
You can push that through one more sort to order the patterns by frequency.
sort file | uniq -c | sort -bn
- Tags:
- Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 08:27 AM
тАО09-27-2004 08:27 AM
Re: find the count
The values can be anything and it is not known to me so that I could serach for the pattern and do a count of that.
What I need to do is find the count of the occurance of each values which are present in the file. The file also has few blank lines.
Thanks,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 08:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 08:42 AM
тАО09-27-2004 08:42 AM
Re: find the count
I tried
sed '/^*$/d' < file|sort|uniq -c > newfile
and it worked.
Thanks to everyone.
-Anand.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2004 08:46 AM
тАО09-27-2004 08:46 AM
Re: find the count
no problems and thanks for taking the time to award points!
Michael