tcl script to extract values from multiple text files having same format and generating column based reports

后端 未结 1 1384
-上瘾入骨i
-上瘾入骨i 2021-01-27 14:50

I have the output logs which are created from Seg-Y files. Example :

TRACE HEADER===============================================================================         


        
相关标签:
1条回答
  • 2021-01-27 15:30

    There a number of ways to do this. Maybe the simplest is just using

    exec <yourexistingscript>

    You know your script pulls the right stuff out, just have Tcl run that.

    Otherwise, here's a basic skeleton of how I write file-parsing code in Tcl when I'm doing it from scratch:

    set fh [open "file.dat", "r"]
    while {[gets $fh line] >= 0} {
      if {<line matches pattern 1>} {
      }
      if {<line matches pattern 2>} {
      }
    }
    close $fh
    

    etc, where the <line matches pattern N> parts are either [string match...] or [regexp ...] lines, depending on the situation. This is basically exactly how awk works. A line-based thing with matches and code to run on them.

    The code inside those matches will also vary depending on the situation, but a typical chunk uses [split] to break the line up by some delimiter. It looks like a space might work here, but I haven't perused your file in detail.

    0 讨论(0)
提交回复
热议问题