- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- count the repeating charcter in a word
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
тАО06-05-2002 12:01 PM
тАО06-05-2002 12:01 PM
I am trying to count the number of times a particular charcter repeated in a word. Could any one help me with a single line command for this problem. TIA
Kris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2002 12:17 PM
тАО06-05-2002 12:17 PM
SolutionTARG="s"
echo "Class" | awk -v targ="${TARG}" '{print gsub(targ,"FurpSplat")}'
In this case, we are looking for how many times
's' appears in "Class". gsub returns the number of substitutions made so that we print '2'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 06:37 AM
тАО06-06-2002 06:37 AM
Re: count the repeating charcter in a word
Here's a good site for many different solutions (although it's word counting):
http://www.bagley.org/~doug/shootout/bench/wordfreq/
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 06:48 AM
тАО06-06-2002 06:48 AM
Re: count the repeating charcter in a word
Here's another shell-silly way:
# WORD=root
# PATTERN=o
# i=1 ; while [ "$i" -lt "`echo $WORD | wc -c`" ] ; do echo $WORD | cut -c$i ; i=`expr $i + 1` ; done | grep $PATTERN | wc -l
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 06:52 AM
тАО06-06-2002 06:52 AM
Re: count the repeating charcter in a word
Okay, you said everything on a single line :P
# WORD=root ; PATTERN=o ; i=1 ; while [ "$i" -lt "`echo $WORD | wc -c`" ] ; do echo $WORD | cut -c$i ; i=`expr $i + 1` ; done | grep $PATTERN | wc -l
2
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2002 07:40 AM
тАО06-06-2002 07:40 AM
Re: count the repeating charcter in a word
# perl -le '$word="Particularity";print$word=~y/i//d'
2