Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pull Specific Data From Block of Data

Status
Not open for further replies.

imFrank

Technical User
Mar 30, 2005
28
US
The four lines below are sample data I am trying to pull out of the blocks of @NAME, @DESC… data. If you examine the @NAME and @DESC data, you will see the data always begin with @NAME and @DATA and they always end with an @FMT statement. Everything else in between is not consistent other than each variable to be evaluated begins with an “@” symbol. The data I’m after are @DESC’s that end in “---X”, “---Y”, or “---Z”. The other @DESC data is not required (like: @DESC: ESS3 MODE or @DESC: 07-10 BATT-2 HEATER EXT PWR CURR MON). I’ve provided sample data with, “---X,Y,Z” and without “---X,Y,Z” data.

When @DESC contains “—X,Y,Z” (like: @DESC: EC10DD002---X SOLID MOTOR #1 CHAMBER PRE), the value of (@ORDER + 1) is required and indicates how many coefficients (@CO:, @C1:, @C2:...) will need to be captured (are associated with) EC10DD002---X.

@DESC @NAME @ORDER + 1 @C0, @C1, @C2, @C3………..
------------- ---------------- -------- ----------------------------------------------------------------------------------------
EC10DD002---X VCSM1_CHMBR_PRS 6 -3.1630863e+00 5.4548164e+00 1.7164921e-02 -1.3902936e-04 5.1083402e-07 -6.9481123e-10
EC13TT002---Z VCENG_LH2_ITMP_L 6 -4.3280551e+02 1.6155632e+00 -2.1858899e-02 1.8099975e-04 -6.9791457e-07 1.0006506e-09
US15SS010---Y VUSBTXTDRSFROABX 2 2.3887317e+01 1.5689024e-01
MC07SS045---X VCBAT_I_1 6 -2.9300203e+00 8.1396875e-01 -1.1731545e-03 1.0239724e-05 -3.5862115e-08 4.9761696e-11


@NAME: ESS3_MODE @STREAM: USERDEF
@DESC: ESS3 MODE @UNITS: COUNTS
@DATAQ_CC @DATAQ_EU
@ENABLE_LIMITS: NO
@PROC_LOC: FRONT END @FEND_NO: 1 @TIME_FMT: BINARY
@RAW_COMP: NONE
@RAW_CONV: NONE
@EU_CAL: NULL
@EU_COMP: NONE
@YEL_LO: 0.000000e+00 @YEL_HI: 1.000000e+00 @RED_LO: -1.000000e-01 @RED_HI: 1.100000e+00
@DYN_LIMS: INACTIVE
@FMT: HEX

@NAME: VCSM1_CHMBR_PRS @STREAM: STR_PCM
@DESC: EC10DD002---X SOLID MOTOR #1 CHAMBER PRE @UNITS: PSIA
@TIME_TAG: NO @ENABLE_LIMITS: YES
@NUM_SYLS: 1
@SYL: 1 @IFRAME: 2 @IWORD: 146 @FR_INC: 2 @WD_INC: 0 @MSB: 7 @LSB: 0
@WD_TYPE: RAW
@RAW_COMP: NONE
@RAW_CONV: NONE
@EU_CAL: NTH @ORDER: 5
@C0: -3.163086e+00 @C1: 5.454816e+00 @C2: 1.716492e-02 @C3: -1.390294e-04
@C4: 5.108340e-07 @C5: -6.948112e-10
@EU_COMP: NONE
@SIM_TYPE: NONE
@YEL_LO: -9.999000e+03 @YEL_HI: 9.999000e+03 @RED_LO: -9.999000e+03 @RED_HI: 9.999000e+03
@DYN_LIMS: ACTIVE @TRANS_LIMS: YES @NUM_EVENTS: 2
@EVENT: 1 @DYN_TRIG: CCPAD_TM_ON_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 9.978700e+03 @DEL_Y_HI: -9.949300e+03 @DEL_R_LO: 9.978700e+03 @DEL_R_HI: -9.949300e+03
@TIME_ON: 2.000000e+00 @TIME_OFF: 2.000000e+00
@ON_Y_LO: 0.000000e+00 @ON_Y_HI: 0.000000e+00 @ON_R_LO: 0.000000e+00 @ON_R_HI: 0.000000e+00
@OFF_Y_LO: 0.000000e+00 @OFF_Y_HI: 0.000000e+00 @OFF_R_LO: 0.000000e+00 @OFF_R_HI: 0.000000e+00
@EVENT: 2 @DYN_TRIG: VCME_STRT_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: -9.978700e+03 @DEL_Y_HI: 9.949300e+03 @DEL_R_LO: -9.978700e+03 @DEL_R_HI: 9.949300e+03
@TIME_ON: 2.000000e+00 @TIME_OFF: 2.000000e+00
@ON_Y_LO: -9.978700e+03 @ON_Y_HI: 9.949300e+03 @ON_R_LO: -9.978700e+03 @ON_R_HI: 9.949300e+03
@OFF_Y_LO: -9.978700e+03 @OFF_Y_HI: 9.949300e+03 @OFF_R_LO: -9.978700e+03 @OFF_R_HI: 9.949300e+03
@ROC: INACTIVE
@FMT: FLOAT @RES: 3

@NAME: VCENG_LH2_ITMP_L @STREAM: STR_PCM
@DESC: EC13TT002---Z ENG LH2 INLET TEMP, LOW RA @UNITS: DEGF
@DATAQ_EU
@TIME_TAG: NO @ENABLE_LIMITS: NO
@NUM_SYLS: 1
@SYL: 1 @IFRAME: 5 @IWORD: 546 @FR_INC: 10 @WD_INC: 0 @MSB: 7 @LSB: 0
@WD_TYPE: RAW
@RAW_COMP: NONE
@RAW_CONV: NONE
@EU_CAL: NTH @ORDER: 5
@C0: -4.328055e+02 @C1: 1.615563e+00 @C2: -2.185890e-02 @C3: 1.809997e-04
@C4: -6.979146e-07 @C5: 1.000651e-09
@EU_COMP: NONE
@SIM_TYPE: NONE
@YEL_LO: -9.999000e+03 @YEL_HI: 9.999000e+03 @RED_LO: -9.999000e+03 @RED_HI: 9.999000e+03
@DYN_LIMS: INACTIVE
@ROC: INACTIVE
@FMT: FLOAT @RES: 3

@NAME: VUSBTXTDRSFROABX @STREAM: VEH_PCM
@DESC: US15SS010---Y S-BAND XMTR TDRSS FWD RF O @UNITS: W
@DATAQ_EU
@TIME_TAG: NO @ENABLE_LIMITS: YES
@NUM_SYLS: 1
@SYL: 1 @IFRAME: 8 @IWORD: 50 @FR_INC: 10 @WD_INC: 0 @MSB: 7 @LSB: 0
@WD_TYPE: RAW
@RAW_COMP: NONE
@RAW_CONV: NONE
@EU_CAL: NTH @ORDER: 1
@C0: 2.388732e+01 @C1: 1.568902e-01
@EU_COMP: NONE
@SIM_TYPE: NONE
@YEL_LO: -9.999000e+03 @YEL_HI: 9.999000e+03 @RED_LO: -9.999000e+03 @RED_HI: 9.999000e+03
@DYN_LIMS: ACTIVE @TRANS_LIMS: YES @NUM_EVENTS: 3
@EVENT: 1 @DYN_TRIG: USANTB_ON_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 1.002900e+04 @DEL_Y_HI: -9.934000e+03 @DEL_R_LO: 1.002900e+04 @DEL_R_HI: -9.934000e+03
@TIME_ON: 3.600000e+02 @TIME_OFF: 3.600000e+02
@ON_Y_LO: 0.000000e+00 @ON_Y_HI: 0.000000e+00 @ON_R_LO: 0.000000e+00 @ON_R_HI: 0.000000e+00
@OFF_Y_LO: 0.000000e+00 @OFF_Y_HI: 0.000000e+00 @OFF_R_LO: 0.000000e+00 @OFF_R_HI: 0.000000e+00
@EVENT: 2 @DYN_TRIG: _T_MINUS_5M_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: -1.002900e+04 @DEL_Y_HI: 9.934000e+03 @DEL_R_LO: -1.002900e+04 @DEL_R_HI: 9.934000e+03
@TIME_ON: 1.000000e-01 @TIME_OFF: 1.000000e-01
@ON_Y_LO: -1.002900e+04 @ON_Y_HI: 9.934000e+03 @ON_R_LO: -1.002900e+04 @ON_R_HI: 9.934000e+03
@OFF_Y_LO: -1.002900e+04 @OFF_Y_HI: 9.934000e+03 @OFF_R_LO: -1.002900e+04 @OFF_R_HI: 9.934000e+03
@EVENT: 3 @DYN_TRIG: _VEH_LMTS_OP_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: -1.002900e+04 @DEL_Y_HI: 9.934000e+03 @DEL_R_LO: -1.002900e+04 @DEL_R_HI: 9.934000e+03
@TIME_ON: 1.000000e-01 @TIME_OFF: 1.000000e-01
@ON_Y_LO: -1.002900e+04 @ON_Y_HI: 9.934000e+03 @ON_R_LO: -1.002900e+04 @ON_R_HI: 9.934000e+03
@OFF_Y_LO: -1.002900e+04 @OFF_Y_HI: 9.934000e+03 @OFF_R_LO: -1.002900e+04 @OFF_R_HI: 9.934000e+03
@ROC: INACTIVE
@FMT: FLOAT @RES: 3

@NAME: ASALARM_HBT_CS @STREAM: CMDSTAT
@DESC: MAPS VEH ALARM HEARTBEAT ENABLE CMD ST @UNITS: CMD ST
@DATAQ_CC
@EU_CAL: NULL
@FMT: FLOAT @RES: 3

@NAME: VCBAT_I_1 @STREAM: STR_PCM
@DESC: MC07SS045---X BATT CURRENT, SYS 1, STG 1 @UNITS: A
@DATAQ_EU
@TIME_TAG: NO @ENABLE_LIMITS: YES
@NUM_SYLS: 1
@SYL: 1 @IFRAME: 1 @IWORD: 17 @FR_INC: 1 @WD_INC: 400 @MSB: 7 @LSB: 0
@WD_TYPE: RAW
@RAW_COMP: NONE
@RAW_CONV: NONE
@EU_CAL: NTH @ORDER: 5
@C0: -2.930020e+00 @C1: 8.139688e-01 @C2: -1.173154e-03 @C3: 1.023972e-05
@C4: -3.586212e-08 @C5: 4.976169e-11
@EU_COMP: NONE
@SIM_TYPE: NONE
@YEL_LO: -9.999000e+03 @YEL_HI: 9.999000e+03 @RED_LO: -9.999000e+03 @RED_HI: 9.999000e+03
@DYN_LIMS: ACTIVE @TRANS_LIMS: YES @NUM_EVENTS: 5
@EVENT: 1 @DYN_TRIG: CCTM_ON_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 9.996000e+03 @DEL_Y_HI: -9.984000e+03 @DEL_R_LO: 9.996000e+03 @DEL_R_HI: -9.984000e+03
@TIME_ON: 3.000000e+00 @TIME_OFF: 3.000000e+00
@ON_Y_LO: 0.000000e+00 @ON_Y_HI: 0.000000e+00 @ON_R_LO: 0.000000e+00 @ON_R_HI: 0.000000e+00
@OFF_Y_LO: 0.000000e+00 @OFF_Y_HI: 0.000000e+00 @OFF_R_LO: 0.000000e+00 @OFF_R_HI: 0.000000e+00
@EVENT: 2 @DYN_TRIG: CCSYS1_INT_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 2.000000e+00 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 2.000000e+00
@TIME_ON: 2.000000e+00 @TIME_OFF: 2.000000e+00
@ON_Y_LO: -9.996000e+03 @ON_Y_HI: 9.984000e+03 @ON_R_LO: -9.996000e+03 @ON_R_HI: 9.984000e+03
@OFF_Y_LO: -9.996000e+03 @OFF_Y_HI: 9.984000e+03 @OFF_R_LO: -9.996000e+03 @OFF_R_HI: 9.984000e+03
@EVENT: 3 @DYN_TRIG: CCID7_TVCPRS_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 3.000000e+00 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 3.000000e+00
@TIME_ON: 2.000000e+00 @TIME_OFF: 2.000000e+00
@ON_Y_LO: -9.996000e+03 @ON_Y_HI: 9.982000e+03 @ON_R_LO: -9.996000e+03 @ON_R_HI: 9.982000e+03
@OFF_Y_LO: -9.996000e+03 @OFF_Y_HI: 9.982000e+03 @OFF_R_LO: -9.996000e+03 @OFF_R_HI: 9.982000e+03
@EVENT: 4 @DYN_TRIG: VCID_LO_SW_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: -9.996000e+03 @DEL_Y_HI: 9.982000e+03 @DEL_R_LO: -9.996000e+03 @DEL_R_HI: 9.982000e+03
@TIME_ON: 1.000000e+00 @TIME_OFF: 1.000000e+00
@ON_Y_LO: -9.996000e+03 @ON_Y_HI: 9.982000e+03 @ON_R_LO: -9.996000e+03 @ON_R_HI: 9.982000e+03
@OFF_Y_LO: -9.996000e+03 @OFF_Y_HI: 9.982000e+03 @OFF_R_LO: -9.996000e+03 @OFF_R_HI: 9.982000e+03
@EVENT: 5 @DYN_TRIG: _VEH_LMTS_OP_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: -9.996000e+03 @DEL_Y_HI: 9.982000e+03 @DEL_R_LO: -9.996000e+03 @DEL_R_HI: 9.982000e+03
@TIME_ON: 1.000000e+00 @TIME_OFF: 1.000000e+00
@ON_Y_LO: -9.996000e+03 @ON_Y_HI: 9.982000e+03 @ON_R_LO: -9.996000e+03 @ON_R_HI: 9.982000e+03
@OFF_Y_LO: -9.996000e+03 @OFF_Y_HI: 9.982000e+03 @OFF_R_LO: -9.996000e+03 @OFF_R_HI: 9.982000e+03
@ROC: INACTIVE
@FMT: FLOAT @RES: 3

@NAME: CCBHTR_EXT2_I @STREAM: GND_PCM
@DESC: 07-10 BATT-2 HEATER EXT PWR CURR MON @UNITS: A
@DATAQ_EU
@TIME_TAG: NO @ENABLE_LIMITS: YES
@NUM_SYLS: 1
@SYL: 1 @IFRAME: 1 @IWORD: 38 @FR_INC: 1 @WD_INC: 0 @MSB: 11 @LSB: 0
@WD_TYPE: RAW
@RAW_COMP: NONE
@RAW_CONV: NONE
@EU_CAL: NTH @ORDER: 1
@C0: -4.479769e-02 @C1: 1.228324e-03
@EU_COMP: NONE
@SIM_TYPE: NONE
@YEL_LO: -3.000000e-01 @YEL_HI: 3.000000e-01 @RED_LO: -5.600000e-01 @RED_HI: 5.600000e-01
@DYN_LIMS: ACTIVE @TRANS_LIMS: YES @NUM_EVENTS: 2
@EVENT: 1 @DYN_TRIG: CCBHTR2_EXTON_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 2.800000e+00 @DEL_Y_HI: 4.000000e+00 @DEL_R_LO: 3.060000e+00 @DEL_R_HI: 3.740000e+00
@TIME_ON: 2.000000e+00 @TIME_OFF: 2.000000e+00
@ON_Y_LO: -9.998700e+03 @ON_Y_HI: 9.998700e+03 @ON_R_LO: -9.998440e+03 @ON_R_HI: 9.998440e+03
@OFF_Y_LO: -9.998700e+03 @OFF_Y_HI: 9.998700e+03 @OFF_R_LO: -9.998440e+03 @OFF_R_HI: 9.998440e+03
@EVENT: 2 @DYN_TRIG: _T_MINUS_60S_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: -1.000150e+04 @DEL_Y_HI: 9.994700e+03 @DEL_R_LO: -1.000150e+04 @DEL_R_HI: 9.994700e+03
@TIME_ON: 1.000000e-01 @TIME_OFF: 1.000000e-01
@ON_Y_LO: -1.000150e+04 @ON_Y_HI: 9.994700e+03 @ON_R_LO: -1.000150e+04 @ON_R_HI: 9.994700e+03
@OFF_Y_LO: -1.000150e+04 @OFF_Y_HI: 9.994700e+03 @OFF_R_LO: -1.000150e+04 @OFF_R_HI: 9.994700e+03
@ROC: INACTIVE
@FMT: FLOAT @RES: 3

Here’s the code I came up with, but it does not give me the results I expected.
My reasoning behind using the if conditions was, I thought I could use the if condition to select the @statements I wanted (and process them) and at the same time it would leave out the @statements I didn’t want. But like I said, I don’t get the results I wanted.


{if ($1~/@NAME/) {n=$2}}
{if ($1~/@DESC/) {d=substr($2,1,15)}
{if ($1~/@EU_CAL/) {c=$4} <<= Here I want @ORDER, but I was using @EU_CAL to get the $4th field.
{if ($1~/@C0/) {a=$0}}
{if ($1~/@C4/) {b=$0}}
print d,n,c,a,b }}




 
Code:
# Record will be all lines up to empty line.
BEGIN { RS=""  }

{ gsub(/[ \t]*\n[ \t]*/, " ")
  gsub( /: */, " " )
  keyshatter( $0, rec, "@[A-Z_0-9]+" )
  if ( "@DESC" in rec && \
        (rec["@DESC"]~/---[XYZ]$/))
  { n = rec["@ORDER"] + 1
    print rec["@DESC"]
    print rec["@NAME"]
    print n
    for (i=0; i<n; i++)
    { suffix = sprintf("%d",i)
      print rec["@C" suffix]
    }
    print ""
  }
}

function x(s)
{ $0 = s ; return $1
}

function shatter( s, shards, regexp )
{ gsub( regexp, "\1&\1", s  )
  return split( s, shards, "\1" )
}

function keyshatter( s, array, regexp,
                    temparray,i,n )
{ n=shatter( s, temparray, regexp ) 
  split( "", array )
  for (i=2; i < n; i+=2)
    array[temparray[i]]= x(temparray[i+1])
}
 
futurelet

I have entered the code as is. It generates output which is very close to what I need. There are two issues.

1. The output is coming out in multiple lines per block of data instead of one line per block of data.

SAMPLE OUTPUT:
MC09AA001---X
VCAFT_CB_ACL_T1
2
-5.137934e+00
4.074357e-02

DESIRED OUTPUT:
MC09AA001---X VCAFT_CB_ACL_T1 2 -5.137934e+00 4.074357e-02



2. There are approximately 16,000 blocks of data. Of those 16,000, approximately 40 cause the following error:
# awk –f read_par.awk PROJECT.par
Input record ‘@NAME: VCHE_OTP_PRG_PRS ...’ too long
Input record number 5568, file PROJECT.par
Source line 1

When I edit the file and delete the block of data that caused the “record too long” error, I can run the script again until if hits the next block that is too long. Then I edit it again and delete the next block and so on.

Here is a sample of a block (one block) of data that is causing the record too long error:
Can the code be modified to handle the larger records?


@NAME: VCHE_OTP_PRG_PRS @STREAM: STR_PCM
@DESC: EC12DD026---X HE ENG OTP/IPS PURGE PRESS @UNITS: PSIA
@DATAQ_EU
@TIME_TAG: NO @ENABLE_LIMITS: YES
@NUM_SYLS: 1
@SYL: 1 @IFRAME: 1 @IWORD: 74 @FR_INC: 1 @WD_INC: 400 @MSB: 7 @LSB: 0
@WD_TYPE: RAW
@RAW_COMP: NONE
@RAW_CONV: NONE
@EU_CAL: NTH @ORDER: 5
@C0: -1.082891e+01 @C1: 3.402359e+00 @C2: -3.570082e-06 @C3: 1.649789e-08
@C4: -7.193419e-10 @C5: 1.250893e-12
@EU_COMP: NONE
@SIM_TYPE: NONE
@YEL_LO: -9.999000e+03 @YEL_HI: 9.999000e+03 @RED_LO: -9.999000e+03 @RED_HI: 9.999000e+03
@DYN_LIMS: ACTIVE @TRANS_LIMS: YES @NUM_EVENTS: 8
@EVENT: 1 @DYN_TRIG: CCTM_ON_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 1.000229e+04 @DEL_Y_HI: -9.970890e+03 @DEL_R_LO: 9.999000e+03 @DEL_R_HI: -9.339000e+03
@TIME_ON: 3.000000e+00 @TIME_OFF: 3.000000e+00
@ON_Y_LO: 0.000000e+00 @ON_Y_HI: 0.000000e+00 @ON_R_LO: 0.000000e+00 @ON_R_HI: 0.000000e+00
@OFF_Y_LO: 0.000000e+00 @OFF_Y_HI: 0.000000e+00 @OFF_R_LO: 0.000000e+00 @OFF_R_HI: 0.000000e+00
@EVENT: 2 @DYN_TRIG: CCPAD_TM_ON_S @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 6.318900e+02 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 0.000000e+00
@TIME_ON: 1.000000e-01 @TIME_OFF: 1.000000e-01
@ON_Y_LO: -1.000229e+04 @ON_Y_HI: 9.970890e+03 @ON_R_LO: -9.999000e+03 @ON_R_HI: 9.339000e+03
@OFF_Y_LO: -1.000229e+04 @OFF_Y_HI: 9.970890e+03 @OFF_R_LO: -9.999000e+03 @OFF_R_HI: 9.339000e+03
@EVENT: 3 @DYN_TRIG: _PAD_CLR_CBC @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 0.000000e+00 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 0.000000e+00
@TIME_ON: 1.000000e-01 @TIME_OFF: 1.000000e-01
@ON_Y_LO: -1.000229e+04 @ON_Y_HI: 9.339000e+03 @ON_R_LO: -9.999000e+03 @ON_R_HI: 9.339000e+03
@OFF_Y_LO: -1.000229e+04 @OFF_Y_HI: 9.339000e+03 @OFF_R_LO: -9.999000e+03 @OFF_R_HI: 9.339000e+03
@EVENT: 4 @DYN_TRIG: CCLH2_VNTS_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 0.000000e+00 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 0.000000e+00
@TIME_ON: 1.000000e+00 @TIME_OFF: 1.000000e+00
@ON_Y_LO: -1.000229e+04 @ON_Y_HI: 9.339000e+03 @ON_R_LO: -9.999000e+03 @ON_R_HI: 9.339000e+03
@OFF_Y_LO: -1.000229e+04 @OFF_Y_HI: 9.339000e+03 @OFF_R_LO: -9.999000e+03 @OFF_R_HI: 9.339000e+03
@EVENT: 5 @DYN_TRIG: CCLO2_VNTS_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 0.000000e+00 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 0.000000e+00
@TIME_ON: 1.000000e+00 @TIME_OFF: 1.000000e+00
@ON_Y_LO: -1.000229e+04 @ON_Y_HI: 9.339000e+03 @ON_R_LO: -9.999000e+03 @ON_R_HI: 9.339000e+03
@OFF_Y_LO: -1.000229e+04 @OFF_Y_HI: 9.339000e+03 @OFF_R_LO: -9.999000e+03 @OFF_R_HI: 9.339000e+03
@EVENT: 6 @DYN_TRIG: CCOTP_8HF_PRS_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 0.000000e+00 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 0.000000e+00
@TIME_ON: 1.000000e+00 @TIME_OFF: 1.000000e+00
@ON_Y_LO: -1.000229e+04 @ON_Y_HI: 9.339000e+03 @ON_R_LO: -9.999000e+03 @ON_R_HI: 9.339000e+03
@OFF_Y_LO: -1.000229e+04 @OFF_Y_HI: 9.339000e+03 @OFF_R_LO: -9.999000e+03 @OFF_R_HI: 9.339000e+03
@EVENT: 7 @DYN_TRIG: CCPOGO_10RVNT_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: 0.000000e+00 @DEL_Y_HI: 0.000000e+00 @DEL_R_LO: 0.000000e+00 @DEL_R_HI: 0.000000e+00
@TIME_ON: 1.000000e+00 @TIME_OFF: 1.000000e+00
@ON_Y_LO: -1.000229e+04 @ON_Y_HI: 9.339000e+03 @ON_R_LO: -9.999000e+03 @ON_R_HI: 9.339000e+03
@OFF_Y_LO: -1.000229e+04 @OFF_Y_HI: 9.339000e+03 @OFF_R_LO: -9.999000e+03 @OFF_R_HI: 9.339000e+03
@EVENT: 8 @DYN_TRIG: _T_MINUS_30S_CS @DYN_OPER: = @DYN_TVAL: 1.000000e+00
@DEL_Y_LO: -1.000229e+04 @DEL_Y_HI: 9.339000e+03 @DEL_R_LO: -9.999000e+03 @DEL_R_HI: 9.339000e+03
@TIME_ON: 1.000000e-01 @TIME_OFF: 1.000000e-01
@ON_Y_LO: -1.000229e+04 @ON_Y_HI: 9.339000e+03 @ON_R_LO: -9.999000e+03 @ON_R_HI: 9.339000e+03
@OFF_Y_LO: -1.000229e+04 @OFF_Y_HI: 9.339000e+03 @OFF_R_LO: -9.999000e+03 @OFF_R_HI: 9.339000e+03
@ROC: INACTIVE
@FMT: FLOAT @RES: 3

Thank you very much for the initial code you provided.
 
2. There are approximately 16,000 blocks of data. Of those 16,000, approximately 40 cause the following error:
# awk –f read_par.awk PROJECT.par
Input record ‘@NAME: VCHE_OTP_PRG_PRS ...’ too long
It works on my computer when I use Kernighan's awk95.
It works on my computer when I use mawk 1.3.3.
It works on my computer when I use gawk 3.0.3.

If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. Under Solaris, use /usr/xpg4/bin/awk.

If one uses an old, obsolete, antique version of awk, he can't expect good results. One should use an awk that has all the features shown in Kernighan's AWK book.

Code:
# Record will be all lines up to empty line.
BEGIN { RS=ORS=""; OFS="\t" }

{ gsub(/[ \t]*\n[ \t]*/, " ")
  gsub( /: */, " " )
  keysplit( $0, rec, "@[A-Z_0-9]+" )
  if ( "@DESC" in rec && \
        (rec["@DESC"]~/---[XYZ]$/))
  { n = rec["@ORDER"] + 1
    print rec["@DESC"], rec["@NAME"], n "\t"
    sep = ""
    for (i=0; i<n; i++)
    { suffix = sprintf("%d",i)
      print sep rec["@C" suffix]
      sep = "\t"
    }
    print "\n"
  }
}

function shatter( s, shards, regexp )
{ gsub( regexp, "\1&\1", s  )
  return split( s, shards, "\1" )
}

function keysplit( s, array, regexp,   i,a_tmp,size )
{
  size = shatter(s, a_tmp, regexp)
  split("", array)
  for (i=2; i<size; i+=2)
  { s = a_tmp[i+1]
    sub( /^[ \t]+/, "", s)
    sub( /[ \t].*$/, "", s)
    array[a_tmp[i]] = s
  }

}
 
futurelet,

I've awk'd, and nawk'd, and gawk'd and pawk'd and everyone around the office is beginning to think I've joined the Natural Wildlife foundation.

Just and FYI - I'm running SGI IRIX version 6.5.21.
And I've tried different awk's on two different veresions of Linux.

Of the different awk's that do not complain about "record too long", they still give me multiple lines of output for each parameter. Do the different versions of awk you mentioned give you one line of output or multiple lines for each parameter?

How can I tell what version of awk I'm running?

I do not get any output with the second awk code you provided. When I enter the awk command, the prompt does not return and I have to Control-C to break out.

I'm going to check around to see what other resources are available to me.
 
A starting point:
Code:
/^@NAME:/{n=$2;a="";next}
/^@DESC:/{d=substr($2,1,15);next}
/@ORDER:/{c=1+$4;next}
/@C[0-9]/{for(i=2;i<=NF;i+=2)a=a" "$i" ";next}
!NF&&c{print d,n,c,a;c=""}
END{if(c)print d,n,c,a}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you both for your excellent suggestions. I also saw another Tek-Tip with a reference to awk95 which I just downloaded. You guys have made my life a lot easier.

PVH - it worked as is - Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top