![]() |
|
|
|
|
|||||||
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CEP vs. “Business Rules” | iBot | Complex Event Processing RSS News | 0 | 10-22-2007 08:00 PM |
| rules | vrn | Post Here to Contact Site Administrators and Moderators | 2 | 03-21-2006 05:25 AM |
| Rules | Tux | Post Here to Contact Site Administrators and Moderators | 2 | 01-20-2005 10:48 AM |
| rules? | Xskwizitboi | UNIX for Dummies Questions & Answers | 1 | 12-02-2004 09:46 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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
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
}
Last edited by yongho; 06-22-2005 at 01:48 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
awk supports arrays.
The Code:
'{ count=0 } ............. { count++ } END { print count }'
Short answer: in awk you can do what you asked. All in one piece of awk code. |
|
|||
|
I see
I'm now considering doing it in the way you suggested, but I have another question about your suggested method.
My problem: Originally I ran something like ls -al | grep Jun 22 | cut -c49-100 >> myLs.txt to give me just the time and filename of all files for June 22nd in a text file. With that text file I began awking. You're suggesting that instead of using while read hour file that I begin the awk right away, to avoid repeating all that code that I did. Since the text file with the LS holds the filenames of CSV files, I need to be able to, at some point, awk those files to perform some count calculations. I don't think I could use a nested awk.. awk within an awk to open those files found in the first awk. (or could I?). I'll pick up the book over the weekend, thanks. Last edited by yongho; 06-23-2005 at 06:53 AM. |
|
|||
|
awk supports the system() function just like in C and php.
You can create a dynamic string, then pass it to system to create output. It's not that awk is better than script or vice-versa - it's just bad to keep using several different tools and bouncing back and forth among them. IMO. |