Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling variable

Status
Not open for further replies.

bgwayatt

Programmer
Joined
Feb 2, 2010
Messages
4
Location
FR
hi,
i have a file with many blocks of data .each block is around 100 lines.
i d like to sum all the first lines together and all the second lines together and so on .
anyone could help me ?
thanks
 
thanks for you r answer.
i feel that it is near to what i want but it is still not working well .i explain with a short example :let us have the following file called file.dat :

1 0.1
2 0.2
3 0.3
4 0.4
5 0.5

1 0.6
2 0.7
3 0.8
4 0.9
5 1.0

1 1.1
2 1.2
3 1.3
4 1.4
5 1.5

1 1.6
2 1.7
3 1.8
4 1.9
5 2.0

1 2.1
2 2.2
3 2.3
4 2.4
5 2.5


and i dlike to have :

1 the sum of all line number 1 in each block
2 the sum of all line number 2 in each block
3 the sum of all line number 3 in each block
4 the sum of all line number 4 in each block
5 the sum of all line number 5 in each block


so what i did is :
awk '{s[$1]+=$2}END{for(i=1;i<6;i++) print i,s}'file.dat>file2.dat

but the result is false .can anyone see the problem ?
thanks
 
Hi

bgwayatt said:
but the result is false .can anyone see the problem ?
Well, I would say the code you posted works with the input data you posted.
I mean, it produces this result, which is the same I expected :
Code:
1 5.5
2 6
3 6.5
4 7
5 7.5


Feherke.
 
what i get is this :

1 4
2 4
3 4
4 4
5 6

which is sure false .
i wonder why it works with you and not with me !
 
What about this ?
Code:
LANG=C awk '...'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
finally i found what was wrong with me .

the program didn't understand "points" in data .so i changed the points by a "comma" and it works fine .


i mean change 0.6 by 0,6 .
thanks for help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top