Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
So, the first row is tab delimited, and other rows following will have four columns(separated by a space) corresponding to a column in the first row separated by a tab. What I neet to do is to get ta out pus similar to this:Individual 301 302 303 304 2003 a b c d a b c d a b c d a b c d 2004 a b c d a b c d a b c d a b c d 2005 a b c d a b c d a b c d a b c d
I have split the file by new lines and have got almost solved with the rest. But thats in a very crude way. Now I have got a tab at the end of each line.below is my code. How could I get rid of my end tab. And also I have got an extra tab inserted in my second row after the first column(in all the lines after that).Individual 301A 301B 302A 302B 303A 303B 304A 304B 2003 c d c d c d c d and similary in the other ones as well
Any suggestion or comments??? Thanks everyone!!!#!/usr/local/bin/perl use strict; use Getopt::Long; my ($sfile, $lfile, $ofile); my (@sampleids); my($loga, $logb, $x, $y) &GetOptions("sfile=s" =>\$sfile, ); unless(open SFILE , $sfile ) {die "cannot open small file: $!\n"}; print "Individual\t"; while(<SFILE>){ chomp; my $line = $_; my @columns = split(/\n/, $line); foreach my $col (@columns) { my @array = split (/\t/, $col); foreach my $a (@array) { next if $a =~ /^Individual/; if ($a =~ /^000\d+/){ print "$a" . "A", "\t", "$a" . "B", "\t"; } } print "\n"; foreach my $b (@array) { next if $b =~ /^Individual/; next if $b =~ /^000\d+/; if($b =~ /^\w+/){ #$b =~ s/^\t//; # $b =~ s/\t$//; print "$b"; } } foreach my $c (@array) { next if $b =~ /^Individual/; next if $b =~ /^000\d+/; next if $b =~ /^\w+/ ; ($loga, $logb, $x, $y) = split (/ /,$c); #$x =~ s/^\t+//; #$x =~s/\t$//; print "$x\t$y\t"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: rearranging the file
by jethro (Monsignor) on Jun 12, 2009 at 12:44 UTC | |
|
Re: rearranging the file
by Timjc86 (Novice) on Jun 12, 2009 at 13:51 UTC |