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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 06-25-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,930
The following works in ksh93 and should also work in bash.
Code:
#!/usr/bin/ksh93

while read str num
do
   strU=${str//[^A-Z]}
   print "${str} ${#strU}"
done < file
On your sample file, it produces the following output
Code:
aabbccddDDCCDDCCaabbcc 8
CCaaCCBBCCaaaaaaaCCCaa 11
CCDDCCAACCCCccccccccaa 12