473,511 Members | 10,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AWK passing output, line by line to variable..

Tarantulus
114 New Member
Hi guys,

ok this is a tough one to explain, but I'll try my best:

I have a CSV file in the format "$date,$value"

what I want to do, is work through the file line by line (I guess piping through AWK to get $date and $value), and while $date does not change add $value to a running total $total$i

when $date changes $i increments so $total$i is a new variable ($total1 becomes $total2)

does this make sense and is it possible?

thanks in advance
Jun 11 '08 #1
4 2566
radoulov
34 New Member
Please provide sample input and example of the desired output.
Jun 11 '08 #2
Tarantulus
114 New Member
sample input:

11/01/2008,312
11/01/2008,200
12/01/2008,600

sample output:

total1 = 512
total2 = 600

OR

11/01/2008 - 512
12/01/2008 - 600

Thanks
Jun 11 '08 #3
radoulov
34 New Member
It the date column is sorted:
(use nawk or /usr/xpg4/bin/awk on Solaris)

Expand|Select|Wrap|Line Numbers
  1. awk -F, 'END { print d, t }
  2. !_[$1]++ && d { print d, t; d = t = "" }
  3. { d = $1; t += $2 }' OFS=\\= filename
Jun 12 '08 #4
Tarantulus
114 New Member
Thanks a lot,

I actually worked it out myself (in a much more convoluted way) but your way is much prettier :)
Jun 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7769
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
2
1566
by: Noel Wood | last post by:
Hello, I have a function I use to remove all the whitespace from the beginning and end of all the $_REQUEST variables. A $_REQUEST variable may also be an array so I call it recursively. I have...
3
14908
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
25
2899
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
11
8095
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
6
5564
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
4
5488
by: cjt22 | last post by:
Hi there. I just wondered whether anyone could recommend the correct way I should be passing command line parameters into my program. I am currently using the following code: def main(argv =...
0
1788
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner;...
1
2650
by: dwaterpolo | last post by:
Hi Everyone, I am trying to read two text files swY40p10t3ctw45.col.txt and solution.txt and compare them, the first text file has a bunch of values listed like: y y y y y y y
4
6628
by: sonu2die4 | last post by:
Hi, I have the following perl script working for me.I am accesing the database from my perl script using use Net::Telnet(); package. I am not using DBI package.as I stated earlier the following...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.