tcl script to extract values from multiple text fi

2019-03-05 01:46发布

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

TRACE HEADER====================================================================================================================
                                                                                MIN            MAX           MEAN          COUNT
Trace sequence number within line                          [001-004]:             1         140400       70200.50         140400
Trace sequence number within SEGY file                     [005-008]:             1         140400       70200.50         140400
Original field record number                               [009-012]:          1001           4900        2950.50         140400
Trace number within original field record                  [013-016]:             1             36          18.50         140400
Energy source point                                        [017-020]:          1001           4900        2950.50         140400
Not used for NFH                                           [021-024]:             0              0           0.00         140400
Hydrophone number in gun source                            [025-028]:             1             18           9.50         140400
Trace identification code                                  [029-030]:             1              1           1.00         140400
No of vertically summed traces yielding this trace         [031-032]:             1              1           1.00         140400
No of horizontally stacked traces yielding this trace      [033-034]:             1              1           1.00         140400
Production1/test2                                          [035-036]:             1              1           1.00         140400
Distance from COS to centre of receiver group              [037-040]:             0             68          22.72         140400
Receiver group depth (scalar #1)                           [041-044]:           460            580         529.82         140400
Tidal observation to vertical datum (scalar #1)            [045-048]:           -82             61           3.00         140400
Source depth (scalar #1)                                   [049-052]:           580            650         613.37         140400
Not used                                                   [053-056]:             0              0           0.00         140400
Not used                                                   [057-060]:             0              0           0.00         140400
Water depth at source (scalar #1)                          [061-064]:        298955         357609      330298.17         140400
Water depth at receiver group (scalar #1)                  [065-068]:        298946         357610      330298.17         140400
Scalar #1 (-ve => divisor)                                 [069-070]:          -100           -100        -100.00         140400
Scalar #2 (-ve => divisor)                                 [071-072]:          -100           -100        -100.00         140400
Source coordinate - X (scalar #2)                          [073-076]:      53664190       53702900    53682718.56         140400
Source coordinate - Y (scalar #2)                          [077-080]:      97593580      107341780   102467937.72         140400
Receiver group coordinate - X (scalar #2)                  [081-084]:      53663450       53703800    53682718.74         140400
Receiver group coordinate - Y (scalar #2)                  [085-088]:      97592690      107342690   102467936.95         140400
Coordinate units                                           [089-090]:             1              1           1.00         140400
Water velocity (as used in p1 water depth)                 [091-092]:          1496           1496        1496.00         140400
Not used                                                   [093-094]:             0              0           0.00         140400
Skew static correction (Scalar #3). Not used for NFH       [095-096]:             0              0           0.00         140400
Water bottom time at CDP/bin centre (Scalar #3)            [097-098]:          3997           4781        4415.75         140400
Source static correction (Scalar #3). Not used for NFH     [099-100]:             0              0           0.00         140400
Receiver group static corr (Scalar #3). Not used for NFH   [101-102]:             0              0           0.00         140400
Total static corr applied (Scalar #3). Not used for NFH    [103-104]:             0              0           0.00         140400
Lag time A. Not used for NFH                               [105-106]:             0              0           0.00         140400
Delay recording time (Scalar #3)                           [107-108]:           -50            -50         -50.00         140400
Original delay recording time. Not used for NFH            [109-110]:             0              0           0.00         140400
Mute time - start (Scalar #3). Not used for NFH            [111-112]:             0              0           0.00         140400
Mute time - end (Scalar #3). Not used for NFH              [113-114]:             0              0           0.00         140400
Number of samples in this trace                            [115-116]:         22529          22529       22529.00         140400
Sample interval for this trace in microsecs                [117-118]:           500            500         500.00         140400
Gain type of field instruments                             [119-120]:             1              1           1.00         140400
Instrument gain - constant. Not used for NFH               [121-122]:             0              0           0.00         140400
Instrument early/initial gain. Not used for NFH            [123-124]:             0              0           0.00         140400
Streamer section serial number. Not used for NFH           [125-128]:             0              0           0.00         140400
Continuous recording shot timer. Not used for NFH          [129-132]:             0              0           0.00         140400
Value obs jitter in aux chan timing. Not used for NFH      [133-134]:             0              0           0.00         140400
Not used                                                   [135-136]:             0              0           0.00         140400
Not used                                                   [137-138]:             0              0           0.00         140400
Not used                                                   [139-140]:             0              0           0.00         140400
Anti-alias filter frequency                                [141-142]:           800            800         800.00         140400
Anti-alias filter slope                                    [143-144]:           240            240         240.00         140400
Not used                                                   [145-146]:             0              0           0.00         140400
Bandpass filter type                                       [147-148]:             0              0           0.00         140400
Low cut filter frequency                                   [149-150]:             3              3           3.00         140400
High cut frequency                                         [151-152]:           800            800         800.00         140400
Low cut filter slope                                       [153-154]:             6              6           6.00         140400
High cut filter slope                                      [155-156]:           240            240         240.00         140400
Year data recorded                                         [157-158]:          2017           2017        2017.00         140400
Day of year data recorded                                  [159-160]:           134            135         134.09         140400
Hour of day data recorded                                  [161-162]:             0             23          17.44         140400
Minute of hour data recorded                               [163-164]:             0             59          29.70         140400
Second of minute data recorded                             [165-166]:             0             59          29.58         140400
Time basis code                                            [167-168]:             4              4           4.00         140400
Not used                                                   [169-170]:             0              0           0.00         140400
This file elevation datum                                  [171-172]:             2              2           2.00         140400
Final survey elevation datum. Not used for NFH             [173-174]:             0              0           0.00         140400
Start time of data ms. Not used for NFH                    [175-176]:             0              0           0.00         140400
End time of data ms. Not used for NFH                      [177-178]:             0              0           0.00         140400
Scalar #3 (-ve => divisor). Not used for NFH               [179-180]:             0              0           0.00         140400
Gun string id number                                       [181-182]:             1              6           3.50         140400
Sailed line sequence number                                [183-184]:           101            101         101.00         140400
Gun mask                                                   [185-186]:             1              2           1.50         140400
Original gun mask                                          [187-188]:             7             56          31.50         140400
Numerical sail line number                                 [189-192]:          4300           4300        4300.00         140400
Receiver cable depth                                       [193-196]:           460            580         529.82         140400
Shot point number                                          [197-200]:          1001           4900        2950.50         140400
Calibration scalar                                         [201-202]:           643           2808        2000.00         140400
Trace value measurement                                    [203-204]:             3              3           3.00         140400
3D inline number                                           [205-208]:          4298           4314        4305.40         140400
3D crossline number                                        [209-212]:         10009          25608       17808.88         140400
Ensemble coordinate - X                                    [213-216]:      53663820       53703350    53682718.65         140400
Ensemble coordinate - Y                                    [217-220]:      97593135      107342235   102467937.34         140400
Gun boat identifier. Not sued for NFH                      [221-222]:             0              0           0.00         140400
Streamer boat identifier. Not used NFH                     [223-224]:             0              0           0.00         140400
Waterbottom time at CDP/bin centre ms                      [225-228]:          3997           4781        4415.75         140400
Source-receiver azimuth                                    [229-230]:             0            359         172.57         140400

There are bunch of these log as one log is created for each Seg-Y file. I have already created a shell script which extracts information from these logs and prints it column wise.

see below link :

http://textuploader.com/d0z0u

The script uses grep and awk mainly.

What I was planning on doing was writing the same script in tcl so that I can have a GUI on Tk and acheive the same functionality using arrays or lists somehow using split but I am new to Tcl and can't get my head around properly extracting information from the logs , I am already working on building the front end GUI just want to get the tcl script sorted so that I can start binding it with GUI.

I want to extract linename , RANGE , FILE etc etc from EBCDIC Header part Line NUmber , Reel NUmber etc from BInary header part and all the MIN-MAX from the Trace Header Part

In my report I want the column names to be the same as row names.

Thanks For help.

标签: bash shell tcl tk
1条回答
何必那么认真
2楼-- · 2019-03-05 02:31

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.

查看更多
登录 后发表回答