Hi all
just like we do group by in SQL for removing duplicate keys, i need to read a file with content as shown below
2010-01-01_audio,4
2010-01-01_text,5
2010-01-01_audio,6
2010-01-01_video,7
2010-01-02_audio,8
2010-01-02_text,6
2010-01-02_video,66
2010-01-02_text,45
Now I need to have one record of 2010-01-01_audio with the value = 4+6. and so on.The record shud look like
2010-01-01_audio,10
So, in short my output shud look like
2010-01-01_audio,10
2010-01-01_text,5
2010-01-01_video,7
2010-01-02_audio,8
2010-01-02_text,51
2010-01-02_video,66
I heard that using hash u cn do it but im not familiar with hash, and if i use the conventional way of using reading the file and foreach record, match it and the write it. but it is not possible to get the expected result.
PS: I cannot provide you with sample code as even I am not able to apply the logic.
any help would be grateful
Thanks
AvantA
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.