Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Check

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-25-2013
SkySmart SkySmart is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 11 May 2015, 5:08 PM EDT
Posts: 677
Thanks: 445
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 Unix and Linux 01-25-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 28 August 2015, 5:52 PM EDT
Location: Saskatchewan
Posts: 20,903
Thanks: 916
Thanked 3,734 Times in 3,487 Posts
Your double-quotes do -- literally -- nothing at all, remove them.
Sponsored Links
    #3  
Old Unix and Linux 01-25-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 29 August 2015, 12:31 PM EDT
Location: Amsterdam
Posts: 10,423
Thanks: 358
Thanked 2,765 Times in 2,471 Posts
Is 5 not the right answer?
    #4  
Old Unix and Linux 01-25-2013
SkySmart SkySmart is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 11 May 2015, 5:08 PM EDT
Posts: 677
Thanks: 445
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 Unix and Linux 01-25-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 29 August 2015, 12:31 PM EDT
Location: Amsterdam
Posts: 10,423
Thanks: 358
Thanked 2,765 Times in 2,471 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 Unix and Linux 01-25-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 28 August 2015, 5:52 PM EDT
Location: Saskatchewan
Posts: 20,903
Thanks: 916
Thanked 3,734 Times in 3,487 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 04:57 PM.