如何从特定行获取全名和编号

How can I get the full name & col number from specific line

我在 table 中有 2 行,如下例所示。 对于每个单词,我都想得到名称和编号。 问题是获取位于 2 行中的全名 "Delay Mean"

如何获取全名和编号?

       Edge   Fanout   Load      Slew        Delay       Delay       Delay       Incr        User     Total    Arrival      Arrival      Arrival      Timing Point                     Cell              Generated Clock        
                                             Mean        Sigma                   Delay       Derate   Derate   Mean         Sigma        Time                                                            Adjustment             

代码:

    foreach line $rpt {
    if {[regexp -all ".*Edge.*Fanout.*" $line]} {
        foreach arg [regexp -all -inline ".*Edge.*Fanout.*" $line] {
                set first_line_table($arg) [lsearch $line $arg]
        }
    }
}

假设单词由 2 个或更多 spaces 分隔,并且每个标题行以 2 个或更多 spaces:

set fh [open $filename r]
set lines [split [read -nonewline $fh] \n]

set indices [regexp -all -indices -inline {\S+(?:\s\S+)?\s{2,}} [lindex $lines 0]]

foreach pair $indices {
    lassign $pair start end
    lappend headings [join [lmap line $lines {
        string trim [string range $line $start $end]
    }]]
}

for {set i 0} {$i < [llength $headings]} {incr i} {
    puts "column [expr {$i+1}] is <[lindex $headings $i]>"
}
column 1 is <Edge >
column 2 is <Fanout >
column 3 is <Load >
column 4 is <Slew >
column 5 is <Delay Mean>
column 6 is <Delay Sigma>
column 7 is <Delay >
column 8 is <Incr Delay>
column 9 is <User Derate>
column 10 is <Total Derate>
column 11 is <Arrival Mean>
column 12 is <Arrival Sigma>
column 13 is <Arrival Time>
column 14 is <Timing Point >
column 15 is <Cell >
column 16 is <Generated Clock Adjustment>

headers 的尾部 space 没有第二行部分。如果不需要,您可以添加另一个 string trim