473,466 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to merge columns from two different files in perl?

2 New Member
Hi,

I have written a following perl script to read particular entities from a text file and avg their timestamp.( I have attached this code as perfresult.txt)

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. my %retrieve;
  4. my $count = 0;
  5.  
  6.   my $file1 = 'a1.txt';
  7.   open (R, $file1) or  die ("Could not open $file1!");
  8.  
  9.   while (<R>) {
  10.  
  11.         next unless /^*Retrieve_generic_/ ||
  12.                   /^*Retrieve_assembly_1_/ ||
  13.                   /^*Retrieve_assembly_2_/ ||
  14.                   /^*300_wireframe_view_/ || 
  15.                   /^*80_wireframe_view_/ ||
  16.                   /^*3_hidden_view_/ || 
  17.                   /^*Fast_HLR_/ || 
  18.                   /^*120_hidden_view_/ ||
  19.                   /^*shaded_view_/ ||
  20.                   /^*shaded_mouse_/ || 
  21.                   /^*realtime_rendered_/;
  22.       $count++;
  23.       my ( $retrieve, $time ) = split;
  24.       my ( $h, $m, $s ) = split ':', $time;
  25.       $retrieve{$retrieve} += $h * 3600 + $m * 60 + $s;
  26.  
  27.   }
  28.   close(R);
  29.   for my $retrieve ( keys %retrieve ) {
  30.       my $hms = secondsToHMS($retrieve{$retrieve} / ( 
  31.       3));
  32.       print "$retrieve\t$hms\n" if defined $hms;
  33.    }
  34.  
  35.   # For seconds < 86400, else undef returned
  36.   sub secondsToHMS {
  37.       my $seconds = $_[0]; 
  38.       return undef if $seconds >= 86400;
  39.  
  40.       my $h = int $seconds / 3600;
  41.       my $m = int( $seconds - $h * 3600 ) / 60;
  42.       my $s = $seconds % 60;
  43.  
  44.       return sprintf( '%02d:%02d:%02d', $h, $m, $s );
  45.   }
  46.  
- I want read to two files (a1.txt and a2.txt)
simultaneously and compare the entities to get the
timestamp difference.(I have attached result.txt for
the output format)
- Please help me to modify my code to get desired output.
Attached Files
File Type: txt a1.txt (2.1 KB, 285 views)
File Type: txt a2.txt (2.1 KB, 244 views)
File Type: txt result.txt (1.1 KB, 300 views)
File Type: txt perfresult.txt (1.2 KB, 308 views)
Dec 15 '12 #1
1 2315
zmbd
5,501 Recognized Expert Moderator Expert
Bytes is not a code writing nor homework service. With the way your current post is written, it is just shy of violating the posting guidlines.

If you will provide the details as to what you are currently getting verses what your current results are then I'm sure someone will nudge you in the right direction.
Dec 16 '12 #2

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

Similar topics

0
by: Mario Fischer | last post by:
Hi! I wrote a small SQL-parser for SELECT-statements for the purpose of easier switching between databases. The parser also works with multiple-table-queries. Until here everything is fine, but...
0
by: Markus Keuthmann | last post by:
I want to export all images from the DB2 sample database (sample) in different files. My export-statement: db2 "export to G:\images\emp_photo.del of del lobs to G:\images\ lobfile image...
1
by: Rico Rivera | last post by:
I have two files: FileA.vb FileB.vb FileA.vb contains the following sample code: NameSpace SomeNamespace Public Class SomeClassA Public Shared Function MethodA() As String
13
by: Kavi | last post by:
I was hoping any javascript and asp gurus may help me with this problem, o.k well here it is.... i have a form, which has a user and password, that a user enters when i want to submit this...
1
by: Mark Denardo | last post by:
Ok here's my problem: I have a bunch of Classes at the same namespace level say "abc.xyz". And all Classes reside in different files. abc.xyz.Class1 (in Class1.vb) abc.xyz.Class2 (in...
1
by: gomzi | last post by:
Hi, I would like to know as to how one could access a function having a same name but in different files. i.e. is there a way of specifying the name of the file so that the function could be...
12
realin
by: realin | last post by:
hi guys, I have a php file say "class.php" in which a database class is defined. I have got another file namely "config.php" which initializes its object as require_once("class.php");...
3
by: ajd335 | last post by:
Hi all, I am using Microsoft 's query analyzer. My query results in a huge number of data. I wanted to store first 500 records into one file.E.g result1.csv and other 500 into result2.csv and so...
1
by: inęs | last post by:
hello! I need help whith perl. I have 2 files, i whant to open them compare one colun and if they iqual i whant to write at the 1Ş file some coluns of the second file. Exemple: File 1 ...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.