UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 8th, 2005, 06:10 PM
Enigma23 Enigma23 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 3 Enigma23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 53 sec
Reputation Power: 0
Question Calculations in C-Script

Given the 2 attached files, I need to calculate which shipper had the most business ( the values under freight in ShippingOrders.tab file) using csh. I thought that the script i created below would give me the totals but it displays nothing. Can someone tell me how to get these values to be displayed? Thanks.

Here is my script:
Code:

set count = 6 # bc there are 5 shippers total
set num = 1

while($num < $count)
     awk '{if($2 ~/$num/) {x+=$5}} END{print x}' ShippingOrders.tab
     @ num = $num + 1
     end
Attached Files
File Type: txt Shippers.tab.txt (202 Bytes, 153 views)
File Type: txt ShippingOrders.tab.txt (3.4 KB, 177 views)

Reply With Quote
  #2  
Old April 19th, 2005, 01:39 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by Enigma23
Given the 2 attached files, I need to calculate which shipper had the most business ( the values under freight in ShippingOrders.tab file) using csh. I thought that the script i created below would give me the totals but it displays nothing. Can someone tell me how to get these values to be displayed? Thanks.

Here is my script:
Code:

set count = 6 # bc there are 5 shippers total
set num = 1

while($num < $count)
     awk '{if($2 ~/$num/) {x+=$5}} END{print x}' ShippingOrders.tab
     @ num = $num + 1
     end


Hello,

I do not know the csh so I might be wrong. I think that you should read the standard input and then pipe the lines into the awk.

In sh or ksh or bash the loop would be :

while read LINE; do
echo $LINE | awk ...
done

Bur here you are calling the awk five times. So you would get five results (possibly empty). The correct way is to pump the standard input directly into the awk, like this:

cat | awk ....

or simply

awk ....

Regards

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Calculations in C-Script


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway