Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-25-2013
Registered User
 
Join Date: Dec 2006
Posts: 495
Thanks: 260
Thanked 1 Time in 1 Post
Check


Code:
echo "2012-12-26--14.8224 2012-12-27--14.2898 2012-12-28--14.9180 2012-12-29--13.3637 2012-12-30--13.7091"

the set of numbers i provided above is separated by spaces. how do i count how many sets there are?

i tried:


Code:
echo "2012-12-26--14.8224 2012-12-27--14.2898 2012-12-28--14.9180 2012-12-29--13.3637 2012-12-30--13.7091" | wc -w

---------- Post updated at 10:57 AM ---------- Previous update was at 10:56 AM ----------

actually never mind, i think i may have found the solution:


Code:
echo ""2012-12-26--14.8224 2012-12-27--14.2898 2012-12-28--14.9180 2012-12-29--13.3637 2012-12-30--13.7091"" | wc -w

notice the double quotes.
Sponsored Links
    #2  
Old 01-25-2013
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
Your double-quotes do -- literally -- nothing at all, remove them.
Sponsored Links
    #3  
Old 01-25-2013
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,338
Thanks: 143
Thanked 1,754 Times in 1,591 Posts
Is 5 not the right answer?
    #4  
Old 01-25-2013
Registered User
 
Join Date: Dec 2006
Posts: 495
Thanks: 260
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Scrutinizer View Post
Is 5 not the right answer?
yes it is. and i got it from using the double quotes.

---------- Post updated at 11:10 AM ---------- Previous update was at 11:09 AM ----------

Quote:
Originally Posted by Corona688 View Post
Your double-quotes do -- literally -- nothing at all, remove them.
if the double quotes are meaningless, please provide a better suggestion.
Sponsored Links
    #5  
Old 01-25-2013
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,338
Thanks: 143
Thanked 1,754 Times in 1,591 Posts
What do you get? I get:


Code:
$ echo "2012-12-26--14.8224 2012-12-27--14.2898 2012-12-28--14.9180 2012-12-29--13.3637   2012-12-30--13.7091" | wc -w
       5
$ echo 2012-12-26--14.8224 2012-12-27--14.2898 2012-12-28--14.9180 2012-12-29--13.3637   2012-12-30--13.7091 | wc -w
       5

I agree with Corona688 that using double double quotes is meaningless..
Sponsored Links
    #6  
Old 01-25-2013
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
Quote:
Originally Posted by SkySmart View Post
if the double quotes are meaningless, please provide a better suggestion.
I suggested removing them. Note that your program works the same either way.

The real question is, what was happening in the first place to make a wrong answer when your quotes make no difference? Either your data or your program must have been unexpectedly different in some way.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl code to check date and check files in particular dir ajaypatil_am Shell Programming and Scripting 1 07-05-2012 08:29 AM
check in and check out comments saku Shell Programming and Scripting 0 02-08-2012 02:00 AM
Check EOF char in Unix. OR To check file has been received completely from a remote system alexalex1 UNIX for Advanced & Expert Users 5 07-22-2010 07:48 PM
script to check if another script is running and if so, then sleep for sometime and check again mathews Shell Programming and Scripting 2 07-21-2010 11:25 PM
Script to check for a file, check for 2hrs. then quit mmarsh UNIX for Dummies Questions & Answers 2 09-16-2005 02:46 PM



All times are GMT -4. The time now is 12:45 PM.