The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
CEP vs. “Business Rules” iBot Complex Event Processing RSS News 0 10-22-2007 11:00 PM
rules vrn Post Here to Contact Site Administrators and Moderators 2 03-21-2006 09:25 AM
Rules Tux Post Here to Contact Site Administrators and Moderators 2 01-20-2005 02:48 PM
rules? Xskwizitboi UNIX for Dummies Questions & Answers 1 12-02-2004 01:46 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-22-2005
yongho yongho is offline
Registered User
  
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Syntax/Rules (Can I do this?)

I have a small piece of code that I need to iterate 24 times (for each hour of a day).... here's what it looks like now...

Code:
while read hour file; do
       
    if [ $hour -eq 00 ]; then
        count=`awk -F, 'BEGIN { count=0 } ............. { count++ } END { print count }' $file`
        hourly01=`expr $hourly1 + $trade_count`
    elif [ $hour -eq 01 ]; then
        count=`awk -F, 'BEGIN { count=0 } ............. { count++ } END { print count }' $file`
        hourly02=`expr $hourly2 + $trade_count`
    ..................
    fi

done < ls.txt
As you can see it's simple, and iterates over and over, but unneccessarily (24 times)... Could I replace all the numbers with one variable... like such..

don't take my code letter for letter, just take the idea and tell me if it can be done..

Code:
for (x=00; x<=23; x++) {
    if [ $hour -eq $x ]; then
        count=`awk -F, 'BEGIN { count=0 } ............. { count++ } END { print count }' $file`
        hourly$x=`expr ${hourly}$x + $trade_count`
    fi
}
Thats' the idea.. I know that I didn't use a unix for-loop, but I just started learning unix and I didn't check what the for looks like in unix yet).. But can I write the middle section (every occurence of $x) the way that I wrote it here?

Last edited by yongho; 06-22-2005 at 04:48 PM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0