Search file by placement of element in a line

76 views Asked by At

I am trying to figure out how to pull a certain element from a file. It always has 4 elements before it but it could have anywhere between none and infinity elements behind it. The element I would like to pull from this file could be named anything but will always be in the same spot per line. the lines of the file are formatted like so...

$(eval $(call CreateTest, file, KeyElement_0 ...
$(eval $(call CreateTest, file, KeyElement_1 ...
$(eval $(call CreateTest, file, KeyElement_2 ...
...
$(eval $(call CreateTest, file, KeyElement_n ...

I want to be able to pull KeyElement and read it to a list but I am currently doing it like this...

proc filterTests path {
    set f [listFromFile $path0/listfile]
    set f [lsearch -all -inline $f "KeyElement_*"]
    return $f
}

This works right now but elements might not necessarily follow the KeyElement_* format so I need to be able to account for this.

EDIT

The code I am using to read from the file look like;

proc listFromFile {$path1} {
    set find {$(eval $(call CreateTest, file, *}
    upvar path1 path1
    set f [open $path1 r]
    while {[gets $f line] != -1} {
        if {[string match ${find} $line]} {
    set write [open listfile a]
    foreach writetofile $line {
    puts $write $writetofile
}
close $write
1

There are 1 answers

1
Peter Lewerin On

Maybe you can try

lsearch -regexp -all -inline $f {^.{32}KeyElement_\S+}

or some such. You will of course have to modify the actual regular expression as needed.

Will expand if useful.