Version 0 of owh - an example

Updated 2021-05-17 15:56:10 by JorgeMoreno

An example for owh
5/17/2021 - I have this very specific format of an (CSV) input file:

+---------+-------+---------------+---------------+---------------+---------------+

Name Group Math Science Biology Chemistry

+---------+-------+---------------+---------------+---------------+---------------+

James A 55.56%(10/18) 74.23%(72/97) 89.47%(34/38) 96.08%(49/51)

+---------+-------+---------------+---------------+---------------+---------------+

Robert A 89.47%(34/38) 64.0%(16/25) 89.47%(34/38) 89.47%(34/38)

+---------+-------+---------------+---------------+---------------+---------------+

John A 85.45%(47/55) 64.86%(24/37) 85.45%(47/55) 89.47%(34/38)

+---------+-------+---------------+---------------+---------------+---------------+

Michael A 56.52%(13/23) 67.74%(21/31) 56.52%(13/23) 85.45%(47/55)

+---------+-------+---------------+---------------+---------------+---------------+

William A 92.86%(13/14) 71.43%(15/21) 92.86%(13/14) 56.52%(13/23)

+---------+-------+---------------+---------------+---------------+---------------+

David A 55.56%(10/18) 69.23%(9/13) 55.56%(10/18) 92.86%(13/14)

+---------+-------+---------------+---------------+---------------+---------------+

Richard A 85.45%(47/55) 64.86%(24/37) 96.08%(49/51) 55.56%(10/18)

+---------+-------+---------------+---------------+---------------+---------------+

Joseph A 56.52%(13/23) 67.74%(21/31) 89.47%(34/38) 85.45%(47/55)

+---------+-------+---------------+---------------+---------------+---------------+

Thomas A 92.86%(13/14) 71.43%(15/21) 89.47%(34/38) 56.52%(13/23)

+---------+-------+---------------+---------------+---------------+---------------+

But I need this other format instead:

+---------+---+-----------+--------+----+----+

James A Math 55.56% 10 18

+---------+---+-----------+--------+----+----+

James A Science 74.23% 72 97

+---------+---+-----------+--------+----+----+

James A Biology 89.47% 34 38

+---------+---+-----------+--------+----+----+

James A Chemistry 96.08% 49 51

+---------+---+-----------+--------+----+----+

Robert A Math 89.47% 34 38

+---------+---+-----------+--------+----+----+

Robert A Science 64.00% 16 25

+---------+---+-----------+--------+----+----+

Robert A Biology 89.47% 34 38

+---------+---+-----------+--------+----+----+

Robert A Chemistry 89.47% 34 38

+---------+---+-----------+--------+----+----+

John A Math 85.45% 47 55

+---------+---+-----------+--------+----+----+

John A Science 64.86% 24 37

+---------+---+-----------+--------+----+----+

John A Biology 85.45% 47 55

+---------+---+-----------+--------+----+----+

John A Chemistry 89.47% 34 38

+---------+---+-----------+--------+----+----+

Michael A Math 56.52% 13 23

+---------+---+-----------+--------+----+----+

Michael A Science 67.74% 21 31

+---------+---+-----------+--------+----+----+

Michael A Biology 56.52% 13 23

+---------+---+-----------+--------+----+----+

Michael A Chemistry 85.45% 47 55

+---------+---+-----------+--------+----+----+

Willian A Math 92.86% 13 14

+---------+---+-----------+--------+----+----+

Willian A Science 71.43% 15 21

+---------+---+-----------+--------+----+----+

Willian A Biology 92.86% 13 14

+---------+---+-----------+--------+----+----+

Willian A Chemistry 56.52% 13 23

+---------+---+-----------+--------+----+----+

David A Math 55.56% 10 18

+---------+---+-----------+--------+----+----+

David A Science 69.23% 9 13

+---------+---+-----------+--------+----+----+

David A Biology 55.56% 10 18

+---------+---+-----------+--------+----+----+

David A Chemistry 92.86% 13 14

+---------+---+-----------+--------+----+----+

Richard A Math 85.45% 47 55

+---------+---+-----------+--------+----+----+

Richard A Science 64.86% 24 37

+---------+---+-----------+--------+----+----+

Richard A Biology 96.08% 49 51

+---------+---+-----------+--------+----+----+

Richard A Chemistry 55.56% 10 18

+---------+---+-----------+--------+----+----+

Joseph A Math 56.52% 13 23

+---------+---+-----------+--------+----+----+

Joseph A Science 67.74% 21 31

+---------+---+-----------+--------+----+----+

Joseph A Biology 89.47% 34 38

+---------+---+-----------+--------+----+----+

Joseph A Chemistry 85.45% 47 55

+---------+---+-----------+--------+----+----+

Thomas A Math 92.86% 13 14

+---------+---+-----------+--------+----+----+

Thomas A Science 71.43% 15 21

+---------+---+-----------+--------+----+----+

Thomas A Biology 89.47% 34 38

+---------+---+-----------+--------+----+----+

Thomas A Chemistry 56.52% 13 23

+---------+---+-----------+--------+----+----+

Then I can use the following owh code (filename cmds.tcl):

 if {$NR == 1} {
        for {set f 1} {$f <= $NF} {incr f} {
         set a($f) [set $f] }
 }
 if {$NR>1} {
        for {set f 3} {$f <= $NF} {incr f 1} {
                if {[string match *%* [set $f]]} {
                        set valor [string map {( ,} [set $f]]
                        set valor [string map {) ,} $valor]
                        set valor [string map {/ ,} $valor]
                        set valor1 $valor
                        puts $1,$2,$a($f),$valor1
                }
        }
 }

launched as follows:

 tclsh owh.tcl "set FS ," "source cmds.tcl" "" <DFPY.csv