Check | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Check

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-25-2013
SkySmart SkySmart is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 17 April 2014, 3:22 PM EDT
Posts: 583
Thanks: 340
Thanked 2 Times in 2 Posts
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
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 April 2014, 6:29 PM EDT
Location: Saskatchewan
Posts: 18,531
Thanks: 681
Thanked 3,036 Times in 2,856 Posts
Your double-quotes do -- literally -- nothing at all, remove them.
Sponsored Links
    #3  
Old 01-25-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 18 April 2014, 3:16 PM EDT
Location: Amsterdam
Posts: 8,874
Thanks: 230
Thanked 2,141 Times in 1,922 Posts
Is 5 not the right answer?
    #4  
Old 01-25-2013
SkySmart SkySmart is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 17 April 2014, 3:22 PM EDT
Posts: 583
Thanks: 340
Thanked 2 Times in 2 Posts
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
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 18 April 2014, 3:16 PM EDT
Location: Amsterdam
Posts: 8,874
Thanks: 230
Thanked 2,141 Times in 1,922 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
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 April 2014, 6:29 PM EDT
Location: Saskatchewan
Posts: 18,531
Thanks: 681
Thanked 3,036 Times in 2,856 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
Closed Thread

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 10:03 PM.