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
Awk:Find length of string omitting quotes jayakumarrt Shell Programming and Scripting 2 05-09-2008 12:48 AM
What the command to find out the record length of a fixed length file? tranq01 UNIX for Dummies Questions & Answers 3 10-19-2007 11:16 AM
read string, check string length and cut ozzy80 Shell Programming and Scripting 9 03-21-2007 01:56 PM
sed problem - replacement string should be same length as matching string. amangeles Shell Programming and Scripting 4 01-11-2006 02:11 AM
length of the string vasikaran UNIX for Dummies Questions & Answers 3 06-30-2005 01:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: May 2008
Posts: 14
Stumble this Post!
find the string length in solaris

how to find the string length in solaris machine.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-10-2008
joeyg's Avatar
premier etoile de match
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 625
Stumble this Post!
Wink putting together a couple of unix commands

Code:
> sample="sample"
> echo $sample | tr -d "\n" | wc -c
6
I used the translate function (tr) telling it to delete new-line (-d "\n") that would normally be part of the variable in this instance. That new-line does the carriage-return and line-feed when you echo it.
Reply With Quote
  #3 (permalink)  
Old 06-10-2008
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,661
Stumble this Post!
Quote:
Originally Posted by din_annauniv View Post
how to find the string length in solaris machine.
Code:
string="a random string with some spaces in it"
echo "The length is ${#string}"
Reply With Quote
  #4 (permalink)  
Old 06-10-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Stumble this Post!
If vino's method doesn't work for you because you're using Bourne Shell, you can also try:

Code:
expr "$string" : ".*"
or

Code:
echo "$string" | awk '{ print length }'
Reply With Quote
  #5 (permalink)  
Old 06-20-2008
Registered User
 

Join Date: May 2008
Posts: 14
Stumble this Post!
thank a lot for ur replies

thank u very much
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:40 AM.


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

Content Relevant URLs by vBSEO 3.2.0