Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing Text

Status
Not open for further replies.

DanBCastro

Programmer
Oct 25, 2012
1
BR
Hi,

I'm learning Perl and I have a challenge to do in Bioinformatics.

I have a CSV file with a lot of columns and rows... but I need to sum cells of certain column:

Samples Name Value1 Value2 Value3.....
A Name 1 32 27 21
B Name 2 23 12 13
C Name 3 10 98 59
D Name 4 21 78 72
E Name 5 32 72 27
... ... ... ... ...

So I need Sum of cells in column Value 1, Sum of cells in column Value2 and so on.

I know this is basic and I'm studying as hard as I can.

Could anyone help me?

Thanks
 
Hi

Code:
perl -nae '[b]if[/b][teal]([/teal]$[teal].==[/teal][purple]1[/purple][teal])[/teal][teal]{[/teal][navy]@h[/navy][teal]=[/teal][navy]@F[/navy][teal];[/teal][b]next[/b][teal]}[/teal][navy]$s[/navy][teal][[/teal][navy]$i[/navy][teal]]+=[/teal][navy]$v[/navy] [b]while[/b][teal]([/teal][navy]$i[/navy][teal],[/teal][navy]$v[/navy][teal])=[/teal][b]each[/b][navy]@F[/navy][teal];[/teal]END[teal]{[/teal][b]print[/b][green][i]"$h[$_] : $s[$_]\n"[/i][/green][b]for[/b] [purple]2[/purple][teal]..[/teal][navy]$#h[/navy][teal]}[/teal]' /input/file


Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top