The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 11-19-2005
Registered User
 

Join Date: Oct 2005
Location: Michigan
Posts: 7
question?

Is there any way to use sed and count the number of alphabetic characters in a sentence?
Reply With Quote
Forum Sponsor
  #2  
Old 11-20-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Is this homework?
Reply With Quote
  #3  
Old 11-20-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
try this,

not thoroughly tested,

Code:
# !/usr/bin/ksh

word="count of no of characters"
cnt=0
curr=""
match=""

while :
do
match=$match"."
if [ curr = `echo $word  | sed -e "s/$match//"` ] 2>/dev/null
then
break;
fi
cnt=$(($cnt + 1))
done
cnt=$(($cnt + 1))

echo "word count: $cnt"
exit 0
Reply With Quote
  #4  
Old 11-20-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
Code:
echo '123abc237R,6|' | sed 's/[^a-zA-Z]//g' | wc -c
Reply With Quote
  #5  
Old 11-21-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
Quote:
Originally Posted by vgersh99
Code:
echo '123abc237R,6|' | sed 's/[^a-zA-Z]//g' | wc -c
the above cnt would include the terminating character also

Code:
count=$((`echo '123abc237R,6|' | sed 's/[^a-zA-Z]//g' | wc -c` - 1))
echo $count
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:48 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