in reply to Re^2: Spliting Table
in thread Spliting Table

This is part of my very nasty code for printing the right stuff for one VP, but it is highly useless for the entire file
No, you almost have it (at least if I understood correctly what you want to do). Your code is reading the file line by line, which is what you need. For each line, you just need to pickup the relevant fields and print them out.

You only need to open a new output file for each input record.

You did not say how you want to name your files, so I will pick up the first field as it seems to be a line number.

while (<REIN>) { chomp(); my @we = split(/\t/); my $out_file_name = "out_file_nr_$we[0]"; open my $RAUS, ">", $out_file_name or die "could not open $out_fil +e_name $!"; my $fix = "$we[0]\t$we[1]\t$we[2]\t$we[3]"; my $out1 = "$we[4]\t$we[5]\t$we[6]\t$we[7]\t$we[8]\t$we[9]\t$we[10 +]\t$we[11]\t$we[12]"; print $RAUS $fix ."\t" .$out1."\n"; close $RAUS; } close(REIN)
I do not understand, though, why you are splitting the data into fields and then join them back into the original format before printing it. So this could be simply:
while (<$REIN>) { my $out_file_name = "out_file_nr_[$.]"; # $. is the line number on + the last read file handle open my $RAUS, ">", $out_file_name or die "could not open $out_fil +e_name $!"; print $RAUS $_; close $RAUS; } close(REIN)
Or did I miss something in your requirement?

Replies are listed 'Best First'.
Re^4: Spliting Table
by poj (Abbot) on Aug 20, 2015 at 13:39 UTC

    As I understand it the input file has hundred of columns like this (transposed)

    Columns Row 1 Row 2 ... etc for 1000s rows Index 1 2 TargetID g00000029 cg00000108 ProbeID_A 14782418 12709357 ProbeID_B 14782418 12709357 VP1.AVG_Beta 0,7469755 0,9218118 VP1.Intensity 2793 3609 VP1.Avg_NBEADS_A 15 12 VP1.Avg_NBEADS_B 15 12 VP1.BEAD_STDERR_A 3,382,405 4,474,464 VP1.BEAD_STDERR_B 7,203,749 1,550,186 VP1.Signal_A 632 190 VP1.Signal_B 2161 3419 VP1.Detection Pval 0,00 0,00 VP2.AVG_Beta 0,6678689 0,9602971 VP2.Intensity 2950 7305 VP2.Avg_NBEADS_A 18 11 VP2.Avg_NBEADS_B 18 11 VP2.BEAD_STDERR_A 9,640,222 3,527,683 VP2.BEAD_STDERR_B 1,268,078 1,308,559 VP2.Signal_A 913 194 VP2.Signal_B 2037 7111 VP2.Detection Pval 0,00 0,00 .. .. repeated for hundreds of VPs

    and the OP wants to create 100's of individual files like this (but transposed)

    File VP1.txt ------------ Index 1 2 ... etc for 1000s rows TargetID g00000029 cg00000108 ProbeID_A 14782418 12709357 ProbeID_B 14782418 12709357 VP1.AVG_Beta 0,7469755 0,9218118 VP1.Intensity 2793 3609 VP1.Avg_NBEADS_A 15 12 VP1.Avg_NBEADS_B 15 12 VP1.BEAD_STDERR_A 3,382,405 4,474,464 VP1.BEAD_STDERR_B 7,203,749 1,550,186 VP1.Signal_A 632 190 VP1.Signal_B 2161 3419 VP1.Detection Pval 0,00 0,00 File VP2.txt ------------ Index 1 2 ... etc for 1000s rows TargetID g00000029 cg00000108 ProbeID_A 14782418 12709357 ProbeID_B 14782418 12709357 VP2.AVG_Beta 0,6678689 0,9602971 VP2.Intensity 2950 7305 VP2.Avg_NBEADS_A 18 11 VP2.Avg_NBEADS_B 18 11 VP2.BEAD_STDERR_A 9,640,222 3,527,683 VP2.BEAD_STDERR_B 1,268,078 1,308,559 VP2.Signal_A 913 194 VP2.Signal_B 2037 7111 VP2.Detection Pval 0,00 0,00
    poj
      As I understand it the input file has hundred of columns like this (transposed)

      Maybe, but that's not what I understood from this post Re^4: Spliting Table's description of the format, which seems to indicate that there are 22 fields for each line.

      Well, this is fairly unclear to me.