从特定行提取信息

时间:2018-05-16 20:09:49

标签: awk

在下面,目的是从特定行提取信息,我用我的代码输出所需的文件,但我在选择时遇到小问题。

/ Live Seis / {s = s“,”substr($ 0,12,1500)}

我选择了12-1500个字段的范围,因为在我的代码中我总是选择最后一个字段,但在此行中此选项不起作用。

是否可以将代码改进或更改为更高效的代码。

输入文件

SCI TB Timestamp Local : 1/2/10 9:54:37.780 AM
File # : 5000
Is Raw : false
Shot # : 754
Swath Name : 1000
Tape # : 2240
Tape Label : X5
Tape Time : 5/4/18 9:55:01.619 AM
Comment : N/A
Line Name : 40559.0
Point Number : 38741.0
Point Index : 1
Easting (m) : 0
Northing (m) : 0
Elevation (m) : 0.0
Source Number : 6
Source ID : 1
SFL : 0
SFN : 0
Spread : 754
Process Type : 0
Nb of Aux : 4
Exploitation Mode : 0
Acq : 1
Correl Pilot : CorrelWith
Type of Test : N/A
Record Type : NORMAL
Acq Length (ms) : 0
Sweep Length (ms) : 0
Record Length (ms) : 0
SR : SR_2_MS
Filter Type : 0
SF : 1
Dump SF : 1
Live Seis : 40560:38466-39172/2(1-354) 40572:38466-39172/2(355-708) 40584:38466-39172/2(709-1062) 40596:38466-39172/2(1063-1416) 40608:38466-39172/2(1417-1770) 40620:38466-39172/2(1771-2124) 40632:38466-39172/2(2125-2478) 40644:38466-39172/2(2479-2832) 40656:38466-39172/2(2833-3186) 40668:38466-39172/2(3187-3540) 40680:38466-39172/2(3541-3894) 40692:38466-39172/2(3895-4248) 40704:38466-39172/2(4249-4602) 40716:38466-39172/2(4603-4956) 40728:38466-39172/2(4957-5310) 40740:38466-39172/2(5311-5664) 40752:38466-39172/2(5665-6018) 40764:38466-39172/2(6019-6372) 40776:38466-39172/2(6373-6726) 40788:38466-39172/2(6727-7080) 40800:38466-39172/2(7081-7434) 40812:38466-39172/2(7435-7788) 40824:38466-39172/2(7789-8142) 40836:38466-39172/2(8143-8496) 40848:38466-39172/2(8497-8850) 40860:38466-39172/2(8851-9204) 40872:38466-39172/2(9205-9558) 40884:38466-39172/2(9559-9912) 40896:38466-39172/2(9913-10266) 40908:38466-39172/2(10267-10620) 40920:38466-39172/2(10621-10974) 40932:38466-39172/2(10975-11328) 40944:38466-39172/2(11329-11682) 40956:38466-39172/2(11683-12036) 40968:38466-39172/2(12037-12390) 40980:38466-39172/2(12391-12744) 
Live Aux : 1-2
Dead Seis : N/A
Missing Seis : N/A
Acq Error : N/A
ITB : N/A
CTB (?s) : N/A
Uphole Time (?s) : N/A
User Header : N/A
Jday : 124
Nb Of Seis : 12746
SCI TB Timestamp GPS Time : 1209452095780002
COG State : COG_ACTUAL
Deviation : 0.5
Cog Easting (m) : 0
Cog Northing (m) : 0
Cog Elevation (m) : 0
Traces Total : 00000
Nb Of Live Seis : 00000
Nb Of Live Aux : 2
Nb Of Dead Seis : 0
Nb Of Missing Seis : 0
Max Of Max Seis : 7.25919534678016E15
Hist Zeroing Length : N/A
________________________________________________________________________
SCI TB Timestamp Local : 2/1/10 9:15:51.580 PM
File # : 5001
Is Raw : false
Shot # : 50
Swath Name : 1000
Tape # : 2240
Tape Label : X5
Tape Time : 5/4/18 9:16:15.011 PM
Comment : N/A
Line Name : 40549.0
Point Number : 39053.0
Point Index : 1
Easting (m) : 0
Northing (m) : 0
Elevation (m) : 0.0
Source Number : 4
Source ID : 1
SFL : 0
SFN : 0
Spread : 50
Process Type : 0
Nb of Aux : 4
Exploitation Mode : 0
Acq : 1
Correl Pilot : 0
Type of Test : N/A
Record Type : NORMAL
Acq Length (ms) : 0
Sweep Length (ms) : 0
Record Length (ms) : 0
SR : SR_2_MS
Filter Type : 0
SF : 1
Dump SF : 1
Live Seis : 40560:38622-39484/2(1-432) 40572:38622-39484/2(433-864) 40584:38622-39484/2(865-1296) 40596:38622-39484/2(1297-1728) 40608:38622-39484/2(1729-2160) 40620:38622-39484/2(2161-2592) 40632:38622-39484/2(2593-3024) 40644:38622-39484/2(3025-3456) 40656:38622-39484/2(3457-3888) 40668:38622-39484/2(3889-4320) 40680:38622-39484/2(4321-4752) 40692:38622-39484/2(4753-5184) 40704:38622-39484/2(5185-5616) 40716:38622-39484/2(5617-6048) 40728:38622-39484/2(6049-6480) 40740:38622-39484/2(6481-6912) 40752:38622-39484/2(6913-7344) 40764:38622-39484/2(7345-7776) 40776:38622-39484/2(7777-8208) 40788:38622-39484/2(8209-8640) 40800:38622-39484/2(8641-9072) 40812:38622-39484/2(9073-9504) 40824:38622-39484/2(9505-9936) 40836:38622-39484/2(9937-10368) 40848:38622-39484/2(10369-10800) 40860:38622-39484/2(10801-11232) 40872:38622-39484/2(11233-11664) 40884:38622-39484/2(11665-12096) 40896:38622-39484/2(12097-12528) 40908:38622-39484/2(12529-12960) 40920:38622-39484/2(12961-13392) 40932:38622-39484/2(13393-13824) 40944:38622-39484/2(13825-14256) 40956:38622-39484/2(14257-14688) 40968:38622-39484/2(14689-15120) 40980:38622-39484/2(15121-15552) 
Live Aux : 1-2
Dead Seis : N/A
Missing Seis : N/A
Acq Error : N/A
ITB : N/A
CTB (?s) : N/A
Uphole Time (?s) : N/A
User Header : N/A
Jday : 124
Nb Of Seis : 15554
SCI TB Timestamp GPS Time : 1209492969580002
COG State : COG_ACTUAL
Deviation : 3.0
Cog Easting (m) : 0
Cog Northing (m) : 0
Cog Elevation (m) : 178.4
Traces Total : 0000
Nb Of Live Seis : 0000
Nb Of Live Aux : 2
Nb Of Dead Seis : 0
Nb Of Missing Seis : 0
Max Of Max Seis : -1.13516329566208E14
Hist Zeroing Length : N/A
________________________________________________________________________

输出文件

21,1000,2240,X5,40559.0,38741.0, 40560:38466-39172/2(1-354) 40572:38466-39172/2(355-708) 40584:38466-39172/2(709-1062) 40596:38466-39172/2(1063-1416) 40608:38466-39172/2(1417-1770) 40620:38466-39172/2(1771-2124) 40632:38466-39172/2(2125-2478) 40644:38466-39172/2(2479-2832) 40656:38466-39172/2(2833-3186) 40668:38466-39172/2(3187-3540) 40680:38466-39172/2(3541-3894) 40692:38466-39172/2(3895-4248) 40704:38466-39172/2(4249-4602) 40716:38466-39172/2(4603-4956) 40728:38466-39172/2(4957-5310) 40740:38466-39172/2(5311-5664) 40752:38466-39172/2(5665-6018) 40764:38466-39172/2(6019-6372) 40776:38466-39172/2(6373-6726) 40788:38466-39172/2(6727-7080) 40800:38466-39172/2(7081-7434) 40812:38466-39172/2(7435-7788) 40824:38466-39172/2(7789-8142) 40836:38466-39172/2(8143-8496) 40848:38466-39172/2(8497-8850) 40860:38466-39172/2(8851-9204) 40872:38466-39172/2(9205-9558) 40884:38466-39172/2(9559-9912) 40896:38466-39172/2(9913-10266) 40908:38466-39172/2(10267-10620) 40920:38466-39172/2(10621-10974) 40932:38466-39172/2(10975-11328) 40944:38466-39172/2(11329-11682) 40956:38466-39172/2(11683-12036) 40968:38466-39172/2(12037-12390) 40980:38466-39172/2(12391-12744) ,1209452095780002
1853,1000,2240,X5,40549.0,39053.0, 40560:38622-39484/2(1-432) 40572:38622-39484/2(433-864) 40584:38622-39484/2(865-1296) 40596:38622-39484/2(1297-1728) 40608:38622-39484/2(1729-2160) 40620:38622-39484/2(2161-2592) 40632:38622-39484/2(2593-3024) 40644:38622-39484/2(3025-3456) 40656:38622-39484/2(3457-3888) 40668:38622-39484/2(3889-4320) 40680:38622-39484/2(4321-4752) 40692:38622-39484/2(4753-5184) 40704:38622-39484/2(5185-5616) 40716:38622-39484/2(5617-6048) 40728:38622-39484/2(6049-6480) 40740:38622-39484/2(6481-6912) 40752:38622-39484/2(6913-7344) 40764:38622-39484/2(7345-7776) 40776:38622-39484/2(7777-8208) 40788:38622-39484/2(8209-8640) 40800:38622-39484/2(8641-9072) 40812:38622-39484/2(9073-9504) 40824:38622-39484/2(9505-9936) 40836:38622-39484/2(9937-10368) 40848:38622-39484/2(10369-10800) 40860:38622-39484/2(10801-11232) 40872:38622-39484/2(11233-11664) 40884:38622-39484/2(11665-12096) 40896:38622-39484/2(12097-12528) 40908:38622-39484/2(12529-12960) 40920:38622-39484/2(12961-13392) 40932:38622-39484/2(13393-13824) 40944:38622-39484/2(13825-14256) 40956:38622-39484/2(14257-14688) 40968:38622-39484/2(14689-15120) 40980:38622-39484/2(15121-15552) ,1209492969580002

我的代码

awk '/File/{if(s){print s;s=$NF+0}else{s=$NF+0}}
    /Swath Name/{s=s","$NF}
    /Tape #/{s=s","$NF}
    /Tape Label /{s=s","$NF}
    /Line Name/{s=s","$NF}
    /Point Number/{s=s","$NF}
    /Live Seis/{s=s","substr($0,12,1500)}
    /SCI TB Timestamp GPS Time/{s=s","$NF}
    END{print s}' file

提前致谢

0 个答案:

没有答案