in reply to how do I manipulate data in csv file

$ echo " 201120 1 05-10-2011_16:47 201120 0 05-10-2011_16:48 201120 1 05-10-2011_16:49 201121 0 05-10-2011_15:47 201121 1 05-10-2011_15:48 201121 1 05-10-2011_15:49 201121 1 05-10-2011_15:50 " | perl -ane'$c{$F[0]}{T}++;$c{$F[0]}{C}+=$ +F[1]}{printf"%s %d %.1f%%\n",$_,$c{$_}{T},$c{$_}{C}/$c{$_}{T}*100 for + sort keys%c' 201120 3 66.7% 201121 4 75.0%

Replies are listed 'Best First'.
Re^2: how do I manipulate data in csv file
by Anonymous Monk on Jul 26, 2011 at 06:15 UTC

    hi thank for your reply, actually I am not really understand your code, I am just a beginner in learning perl. can i know what if i have a csv file like below?

    week power test Test_end_date_time 201120 5 1 05-10-2011_16:47 201120 699 17 05-10-2011_16:48 201120 454 1 05-10-2011_16:49 201121 5687 26 12-10-2011_15:47 201121 211 1 12-10-2011_15:48 201121 1231 36 12-10-2011_15:49 201121 171 1 12-10-2011_15:50 201121 677 57 12-10-2011_15:51 201121 178 1 12-10-2011_15:52 if test = 1 mean pass, other than 1 is fail I wish the output in another csv is like below, any guides for me? week volume yield 201120 3 66.7% 201121 6 50.0%
      $ echo " week power test Test_end_date_time 201120 5 1 05-10-2011_16:47 201120 699 17 05-10-2011_16:48 201120 454 1 05-10-2011_16:49 201121 5687 26 12-10-2011_15:47 201121 211 1 12-10-2011_15:48 201121 1231 36 12-10-2011_15:49 201121 171 1 12-10-2011_15:50 201121 677 57 12-10-2011_15:51 201121 178 1 12-10-2011_15:52 " | perl -ane'/^\D/&&next;$c{$F[0]}{T}++;$c{$F[0]}{C}+=$F[2]==1}{print +f"%s %d %.1f%%\n",$_,$c{$_}{T},$c{$_}{C}/$c{$_}{T}*100 for sort keys% +c' 201120 3 66.7% 201121 6 50.0%

        Thank you very much, it is very helpful