Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Merging two files and changing format

by choroba (Canon)
on Oct 11, 2012 at 15:13 UTC ( #998473=note: print w/ replies, xml ) Need Help??


in reply to Merging two files and changing format

You can read from both input files simlultaneously:

#!/usr/bin/perl use warnings; use strict; open my $IN1, '<', 'infile_1' or die $!; open my $IN2, '<', 'infile_2' or die $!; open my $OUT, '>', 'test2' or die $!; while (my $in1 = <$IN1>) { chomp $in1; defined(my $in2 = <$IN2>) or die "file2 too short\n"; $in2 =~ s/\s//g; print {$OUT} join("\t", split /\s+/, $in1), "\t", join("\t", split + //, $in2), "\n"; } die "file1 too short\n" if <$IN2>; close $OUT;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Merging two files and changing format
Download Code
Reaped: Re^2: Merging two files and changing format
by NodeReaper (Curate) on Oct 11, 2012 at 18:28 UTC
Re^2: Merging two files and changing format
by webby01 (Initiate) on Oct 11, 2012 at 18:32 UTC

    this code gives me a file with 805948 rows, when the desired amount of rows is 660918.

Re^2: Merging two files and changing format
by webby01 (Initiate) on Oct 11, 2012 at 18:37 UTC

    i think the problem is that some entries are -- instead of, 'AA' for example in the case of missing data. Are there any modifications I can make to the code to remedy this? Thank you.

      Please, show an example of a pair of lines that is not processed correctly.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        your code is printing extra blank lines between lines of good output

        sed -n '1, 5{=;p;}' test2

        1

        M MitoA10045G 0 10045 A A A A...

        2

        3

        M MitoA10551G 0 10551 A A A A ...

        4

        5

        M MitoA11252G 0 11252 A A A A ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2015-07-06 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls