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
swap words in a line with sed atticus Shell Programming and Scripting 9 09-13-2008 08:09 AM
swaping of first 2 words in every line using sed web123 Shell Programming and Scripting 4 05-28-2008 06:02 AM
How to append words at the end of first line lmatlebyane Shell Programming and Scripting 11 02-28-2008 01:39 AM
seperating the words from a line?? skyineyes Shell Programming and Scripting 3 06-26-2007 06:00 AM
How to grep for two or more words in a line at the same time? ElCaito Shell Programming and Scripting 2 03-01-2006 08:48 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-20-2008
Registered User
 

Join Date: Mar 2007
Posts: 34
Post count no of words in a line

hi
i have a string like
str=abc def ghi jkl

now i want to count the no of words in the string
please help
Reply With Quote
Forum Sponsor
  #2  
Old 05-20-2008
Registered User
 

Join Date: Apr 2008
Location: Bangalore
Posts: 123
echo "abc def ghi jkl" | wc -w


Thanks
Penchal
Reply With Quote
  #3  
Old 05-20-2008
Registered User
 

Join Date: Dec 2006
Posts: 28
Quote:
Originally Posted by satish@123 View Post
hi
i have a string like
str=abc def ghi jkl

now i want to count the no of words in the string
please help
Like this:
str="abc def ghi jkl"
echo $str|wc -w
Reply With Quote
  #4  
Old 05-20-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
satish,

I have question, are trying before posting?
Reply With Quote
  #5  
Old 05-20-2008
Registered User
 

Join Date: Mar 2007
Posts: 34
Post counting no of wordds in a line

hi elthox
it is working fine but i want to assign the count to a variable
i am doing

var= abc def ghi jkl mno | wc -w
echo "------------------->"$var

it is throwing an error please help
Reply With Quote
  #6  
Old 05-20-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
Code:
var=$(echo "abc cb fg" | wc -w)
Reply With Quote
  #7  
Old 05-20-2008
Registered User
 

Join Date: Mar 2007
Posts: 34
Post counting no ofwords in a line

hi aju
i am trying and then only i am asking
i am a java resource, my project people gave me the sript to remove the queues from the cluster
so i am in hurry thats why i am asking
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:58 PM.


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