collecting data from file
Mustafa Celik
mustafa.celik at sympatico.ca
Fri Apr 11 11:07:15 EDT 2003
The file that I'm analyzing guarantees to have >4 columns, and lines
contain string, integer, float..., they are seperated by spaces.
An example line is as below:
1850099.32 HELLO 0xfce 6 OTTAWA stree_number_200 exit_Metcalfe
take_hw_417 arrive_at_Ottawa_Airport
2nd column will tell me if someone has arrive, 3rd column will tell me
how much $ they'll bring with them, and 4th column will tell who he is
(a hex guy).
I will find out;
* how many people arrived and did not leave,
* how many have arrived and left
* how much we have in Ottawa at the end
* how much transient money flow have occured
My file may contain some lines that only leaves Ottawa, so I should
ignore them (they probably arrived earlier, and should not decrement my
dollar gain) - This condition is not very important, if it'll
complicate things, I have other ways to prevent this.
I found a good awk document last night (can't remember the web site), I
was planning to dig in it today, but you guys have supported me with my
initial plan with Python. I'm not a beginner in Python, this is probably
not the best project to start with, but I need to have this done by Awk
or Python, ...
Thanks,
Mustafa
Peter Hansen wrote:
> Mustafa Celik wrote:
>
>>I want to scroll thru a file;
>> * find lines that match a string (e.g. HELLO) on the 2nd column
>> * add up the 4th column (an integer) on each matching line, say the
>>variable is TOTAL
>> * subtract the 4th column from TOTAL if another is string (e.g. BYE)
>>is hit on 2nd column of a line
>>
>>Any tips?
>
>
> Yes, post an example showing what you intend. The instructions are
> decent, but implementable only by making a few assumptions about what
> you mean. Also, are there any error conditions to be handled, or do
> you guarantee the input is always perfect (e.g., always at least four
> columns, and so on)?
>
> -Peter
More information about the Python-list
mailing list