473,383 Members | 1,863 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,383 software developers and data experts.

How to make sequential data into a group

Hi all,
I am a newbie to Perl. Appreciate anybody can give me some suggestions and help here.

I have a file:
___________________
A1a01 A1a03
A1a03 A1a0b
A1a0b A1a2a
A1a2a A1a02
A1app A1a06
Ala06 A1a07
A1b0v A1b0c
Alb0c Alb55
A1b55 A1b04
.. ..
.. ..
.
.
.

I want to extract and print the sequential data into different groups. As you can see from the example given, the groups are from A1a01 to A1a02, A1app to A1a07, and A1b0v to A1b04. Each group is in sequential manner.

So far I have tried the code below, but it doesn't work to get what I need. I only manage to print those matched names after comparison of column1 and column2. I do not have idea how to extract the non-match names. (not sequential in order after compare column1 2nd name with column2 1st name of 2 rows data.) And I need to print each group first and last names.



Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my $i;
  5. my $j;
  6. my @column1;
  7. my @column2;
  8. my @array1;
  9. my $lastname;
  10.  
  11.  
  12. @column1=`awk '{print \$1}' saved4`;
  13. @column2=`awk '{print \$2}' saved4`;
  14.  
  15.     for ($i=0;$i<=$#column1;$i++){
  16.         for ($j=0;$j<=$#column2;$j++){
  17.                 if ($column1[$i]=~ /$column2[$j]/){
  18.  
  19.                    push (@array1,$column2[$j]); 
  20.                            }
  21.  
  22.         else {
  23.             $lastname = $column2[$j];
  24.             }
  25.  
  26.             }
  27. }
  28.  
  29. print "$column1[0] @array1 $lastname\n";



The expected result is like:

group1:
A1a01 A1a03
A1a03 A1a0b
A1a0b A1a2a
A1a2a A1a02

group2:
A1app A1a06
Ala06 A1a07

group3:
A1b0v A1b0c
Alb0c Alb55
A1b55 A1b04
Jan 21 '13 #1
0 1234

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

Similar topics

0
by: Lilian BRUN | last post by:
I have a table State_history : Id State DateModif object_id 1 A 10/10/01 1 2 B 10/11/01 1 3 B 11/11/01 1 4 B 11/12/01 1 5 C ...
2
by: tom cubbins | last post by:
let's make a news group for Virtual Server 2005. put it perhaps in the enterprise development area. i like that software and would like to see what other's people experience with it. tom...
1
by: Alok Kumar | last post by:
Hi guys! I'm facing some problem with the data grid. My table data is something like this Group Name isMarried
9
by: PengYu.UT | last post by:
Hi, I write the content of a in file "data" (in Sun Machine). Then I read "data" in both SunOS and linux. But the result is different. Do you know how to make it binary data portable. Best...
1
by: Pratchaya | last post by:
Hi, All I want to make transfer data between MySQL Server to MySQL Local . My Environment. Server < --- > My PC Client Server = ::::: MySQL DB Server ( for Linux )
0
by: Henry | last post by:
I am trying to create a TreeView control that works with an ADO Dataset DataTable or the new BindingSource stuff in .NET 2.0 to build a Treeview that is populated. This is what I came up with...
0
by: Ryan Liu | last post by:
Hi, I notice a DataRow in Detached when it is just created by dataTable.NewRow(), and when added to a dataTalbe's row collection, then removed from that collection. For the first situation, I...
5
by: P | last post by:
I was wondering what sort of changes I need to make in order to make an application to be DEP compatible with on Windows XP x64 version 2003. I have compiled an open source C application...
2
by: DubSport | last post by:
I have created a datatable in a function, and it is populated with data. I want to call a new function from an ASP button, and write out some of the values in the datatable, using: string...
6
by: xkenneth | last post by:
All, Just a quick question. I want to be able to have a data structure that organizes data (timestamps I'm working with) sequentially, so that i can easily retrieve the first x amount of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.