Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^3: average a column in tab-delimited file

by naturalsciences (Beadle)
on Jan 27, 2012 at 17:28 UTC ( #950421=note: print w/replies, xml ) Need Help??

in reply to Re^2: average a column in tab-delimited file
in thread average a column in tab-delimited file

To make life easier for you I will post a piece of code in here. Earlier today I had to transpose a large text file so I blurted out this piece of code. (Takes the rows from a file and makes them into a column)

It is a rather stupid code. (I'm a noob). For example it would not be prudent to actually load all the file into an array, but better to do it line by line in a while($line=<>) loop. etc. But Being a rather stupid code it should also be quite readily understandable and demonstrates the idea of getting columns out from your lines pretty well.

#!/usr/bin/perl -w use strict; use warnings; my @data=<>; my @column=(); for (my $count=3;$count<=4215;$count++) { foreach (@data) { my @row=split(/\t/, $_); push (@column,$row[$count]); } print "@column\n"; @column=() }

As you can see this piece of code was used to extract columns 3 to 4215. You only need to extract one single column right now. Enjoy!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950421]
[choroba]: Good morning!
[Discipulus]: good morning choroba! the eu-crew is complete! ;=)
mxb waves

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2018-05-21 08:03 GMT
Find Nodes?
    Voting Booth?