473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Grouping with Perl

2
Hi,

I am having some difficulty thinking of a way to do something that I'm sure is simple. I, however, just cannot get my brain around a way to get Perl to do it. What I have is a file with multiple records. The records contain an ID, name, description, application in that order. There are in some cases several of the same ID listed because one ID may have more than one application. What I want to do is print out the same data to anohter file but I want the ID's listed only once and all of the applications listed in the one line. So basically the data looks like this:

ID, name, description, application
1, XYZ, desc, PDF
1, XYZ, desc, QFZ
2, YGH, desc, LMN

What I'm looking for is:

1, XYZ, desc, PDF,QFZ
2, YGH, desc, LMN

I have been trying to think of a good way to do this for a while and haven't come up with anything. If anyone could help, I'd very much appreciate it.
Sep 10 '08 #1
3 2676
numberwhun
3,509 Expert Mod 2GB
Just so we know how far you have gotten in your attempts to do this, why not post the code you have been working with, here, enclosed in code tags, and we will help you get it working from there.

Regards,

Jeff
Sep 10 '08 #2
eWish
971 Expert 512MB
I would suggest that you use a hash of hashes.

--Kevin
Sep 10 '08 #3
de2425
2
Just so we know how far you have gotten in your attempts to do this, why not post the code you have been working with, here, enclosed in code tags, and we will help you get it working from there.

Regards,

Jeff
I already got the code going. Thanks for the helpful reply though. The code that ended up working, in case anyone else runs across this type of situation, is:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. open (IN, "input file");
  4.  
  5. while(<IN>){ 
  6.      chomp;
  7.       @t=split(/\t/,$_);
  8.       $AB{$t[0]}=$AB{$t[0]}.",$t[2]";
  9.       }
  10.       print %AB;
  11. close IN;
  12. close OUT;
  13.  
  14.  
  15. open (OUT, ">output file");
  16. open (IN, "input file");
  17.  
  18. while (<IN>){
  19.       chomp;
  20.       @Products=split(/\t/,$_);
  21.  
  22.       if ($Products[0] and exists $AB{$Products[0]}){
  23.       print OUT "$Products[0]\t$Products[2]\t$AB{$Products[0]}\n";
  24.       }
  25. }
  26.  
  27. close IN;
  28. close OUT;
Sep 10 '08 #4

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

Similar topics

1
by: amber | last post by:
Hello, I have a report in VB.NET/Crystal Reports. I have a criteria form that users select between 2 different types of grouping (group by category or group by year). Can I programmatically...
2
by: Andreas Håkansson | last post by:
Seeing how my previous post seem to have fallen between the cracks, I thought I would have a second, more direct, go at it. So my question is "Is it possible to group (Muenchian method) over...
3
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
5
by: Tom | last post by:
- matches "a", "b", or "c" - matches anything except "a", "b", and "c" (abc) - matches "abc", with back reference ??? - matches anything except "abc" literally?? What is the syntax for this...
0
by: Corey | last post by:
hello, I’m trying to run a query and I’m getting error messages Can anyone help me get though this problem? 1: Tried this and got this error message ORA-00923 , decode...
0
by: Roman Bertle | last post by:
Hello, I try to format monetary values using the locale module, python2.5: Python 2.5.2a0 (r251:54863, Jan 3 2008, 17:59:56) on linux2 Type "help", "copyright", "credits" or "license" for...
1
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" ...
6
patjones
by: patjones | last post by:
Good afternoon: This seems like it shouldn't be hard, and then again this is how so many problems seem at the outset. My situation is this: I have a report called rptMain319, which is based...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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,...

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.