ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
But I do not know how to implement counting in this case in other words how count ( on some case ) all values for a and then print them
( print them is an easy part )
The critical part is {a=a+1} I do not understand this. I am new on this position.
I probably wrote bad explanation of my problem ,,,I have folloving situation
fileA something like
x1 x2 x3 x4 x5 x6 x7
33 324 43 5454 54 54 545
345 55 5 4233 4 4 4
...........................
............................
x4 column represents phone numbers fied, and column x5 represents how many calls were sent to that number. Other fields are not interested. Using awk I have to calculate how many calls were past to every phone number. In output file I have to get something like bellow
x4 x5
5454 54
3244 4
... ...
... ...
and so on for every phone number.
I can sort phone numbers to files and numbers of calls, but I do not know how to count calls for every particular number.
If someone know, or have some hint how to do this, please write it down.
This is not as simple as it might look, especially when confined to using awk ( and one or two other unix tools). Personally I would choose perl to tackle this.
But.......
It can (partially) be done as a 'one-liner' using awk and sort:
#!/usr/bin/python
store = {} #store results
for line in open("file"):
line = line.strip().split()
phone,freq = line[3],line[4]
if not store.has_key(phone):
store[phone] = 0
store[phone] = store[phone] + int(freq)
for i,j in store.iteritems():
print i, j
What means show all calls for particular phone number.
Druuna thank you anyway.
Regards
My boss .... Column X5 represent duration of call and solution I got by Druuna works ok, but now I have to make somethig like
x4 Some column
9333007 5 (1+1+1+1+1=5)
9000229 3(1+1+1 )
9001220 1(only one call)
They need how many calls were sent. For example for number 9333007 I had 5 calls, first lasted 7min, second 8 min, third 9 min, fourth 7 min, fifth 9 min and do same for all numbers.
Confusing isn't it ?
Regards
Thank you
Your examples and explanation are indeed confusing......
This:
9333007 7
9333007 9
9000229 9
9001220 7
Only shows phonenumber and amount of calls. Where does the duration of the call come from (You stated: 9333007 had 5 calls, first lasted 7min, second 8 min........)??
END {print " 93120000 ", t}
END {print " 90003237 ", z}
END {print " 90003238 ", b}
END {print " 90003239 ", d}
END {print " 90013230 ", e}
END {print " 91005535 ", f}
END {print " 91006536 ", g}
END {print " 91005377 ", h}
END {print " 90034324 ", i}
END {print " 92006344 ", j}'
And this print all vales for every number. Thank you Druuna very much for your help, and sory again for my messy posts.
It is other story that this solution is not nice to see, but it works on some dusty server, and no one will see it....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.