Let me explain more clearly now. I ask some days ago about to join two files with conditional and loop. I got to solve partially the problem but I need to change these demand to the following situation.
File A with 9 or more lines and the second column is the key.File B with 800 or more lines and the second column is the key.life_1,23032018,a_0300,true,3 life_1,23032018,a_0200,true,4 life_1,23032018,a_0100,true,3 life_1,23032018,c_0300,true,21 life_1,23032018,c_0200,true,21 life_1,23032018,c_0100,true,25 life_1,23032018,d_0300,true,23 life_1,23032018,d_0200,true,21 life_1,23032018,d_0100,true,24
I am using Perl in the File A and using the 5th column to run through the number of lines of the File B and creating a third file. But when the for loop of the 5th column from File A finish I have to stop in the line in the File B and continue the next loop in the same line and not to restart from the First line in File B. The result I got with my script is. The second column values are repeated on each loop. For example, the value 201810021569661 is showing 3 times in my result.201810021569661,23032018 201810021569678,23032018 201810021569685,23032018 201810021569708,23032018 201810021569715,23032018 201810021569722,23032018 201810021569739,23032018 201810021569746,23032018 201810021569753,23032018 201810021569760,23032018
The result I want is this. Look the result is the second column does not repeat. Now the value 201810021569661 is showing only one time.Loop tot->3 life_1,201810021569661,a_0300 life_1,201810021569678,a_0300 life_1,201810021569685,a_0300 Loop tot->4 life_1,201810021569661,a_0200 life_1,201810021569678,a_0200 life_1,201810021569685,a_0200 life_1,201810021569739,a_0200 Loop tot->3 life_1,201810021569661,a_0100 life_1,201810021569678,a_0100 life_1,201810021569685,a_0100
With the help of all of you, I did something but it is restarting the File B on each loop.Loop tot->3 life_1,201810021569661,a_0300 life_1,201810021569678,a_0300 life_1,201810021569685,a_0300 Loop tot->4 life_1,201810021569708,a_0200 life_1,201810021569715,a_0200 life_1,201810021569722,a_0200 life_1,201810021569739,a_0200 Loop tot->3 life_1,201810021569746,a_0100 life_1,201810021569753,a_0100 life_1,201810021569760,a_0100
use strict; use warnings; use Data::Dumper qw(Dumper); my $filea = FileA; my $fileb = FileB; open ( FA, '<', $filea) || die ( "File $filea Not Found!" ); open ( FB, '<', $fileb) || die ( "File $fileb Not Found!" ); my %ts; while ( <FB> ) { chomp; my($ids, $timestamp) = split ","; push @{ $ts{$timestamp} }, $ids; } while ( <FA> ) { chomp; my($life,$timestamp,$cls,$bool,$tot) = split ","; print STDERR "Loop tot-> $tot"; scalar <STDIN>; for my $ids ( @{ $ts{$timestamp} } ) { last if $tot-- < 1; print join(",",$life, $ids, $cls )."\n"; } }
In reply to Perl to run 2 files and print the third with loop by EBK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |