Replacing first word while extracting

Hello All,

I am extracting a part of file. the file looks as follows

USING CHARACTER SET UTF8 DEFINE JOB 

(

DEFINE SCHEMA Flat_File_Schema
(
  cntnt_id VARCHAR(10)
);

DEFINE OPERATOR o_mload
 TYPE update
 SCHEMA *
 ATTRIBUTES
  (
    VARCHAR TdpId           = @TdpId
  );
DEFINE OPERATOR o_tpump
 TYPE stream
 SCHEMA *
 ATTRIBUTES
  (
    VARCHAR TdpId           = @TdpId
  );
DEFINE OPERATOR o_bteq
 TYPE inserter
 SCHEMA *
 ATTRIBUTES
  (
    VARCHAR TdpId           = @TdpId
  );
DEFINE OPERATOR o_fastload
 TYPE load
 SCHEMA *
 ATTRIBUTES
  (
    VARCHAR TdpId           = @TdpId
   ,VARCHAR UserName        = @UserName 
  );
DEFINE OPERATOR Read_Operator
 TYPE DATACONNECTOR PRODUCER
 SCHEMA Flat_File_Schema
 ATTRIBUTES
  (
    VARCHAR FileName         = @FileName 
);

APPLY
( 'INSERT INTO cntnt_cat_itm (
  cntnt_id
 ,cat_itm_nm
 ,prnt_cat_itm_nm
 ,updt_dt_tm
 ,load_dt_tm
 ,src_tbl_nm
 ,trans_type_cd
 ,jrnl_seq_nbr
 ,commit_locl_tm_zn
 ,batch_dt
 ,batch_id
 ) VALUES
(
 :cntnt_id
 
 
 );'
)
    IGNORE DUPLICATE ROWS
    SELECT * FROM OPERATOR (Read_Operator[@ReadInst]);
);

I want to extract the part of file highlighted in green color,
I did it this way

awk '/DEFINE SCHEMA/,/\)\;/ {if (NF==2) print}'  filename

Now I want to replace the first word of each line in extract with values increamenting t1 as filler, t2 as filler, t3 as filler
so in this case the output should look like this

t1 as filler VARCHAR

There will more more line in extract instead of only one as shown here
Please help me getting this.

Like that?

bash-3.2$ awk 'BEGIN{x=1} /DEFINE SCHEMA/,/\)\;/ {if (NF==2) { $1="t"x" as filler"; print; x++ }}' filename
t1 as filler VARCHAR(10)
1 Like
awk '{print "t"++i" as filler VARCHAR"}' extract_file
1 Like

Hello MR.Bean

That was exactly what I was looking for.

Can you please take some time and explain me how this works.

Thanks in Advance

bash-3.2$ awk 'BEGIN{x=1} /DEFINE SCHEMA/,/\)\;/ {if (NF==2) { $1="t"x" as filler"; print; x++ }}' filename
BEGIN{x=1}

Assign x with value "1". Then goes through the file.

/DEFINE SCHEMA/,/\)\;/

If it is within "DEFINE SCHEMA" and ");", it would be true (highlighted in red).

USING CHARACTER SET UTF8 DEFINE JOB 
 
(
 
DEFINE SCHEMA Flat_File_Schema
(
cntnt_id VARCHAR(10)
);
 
DEFINE OPERATOR o_mload
 TYPE update
 SCHEMA *

The if statement below looks for lines with 2 fields (highlighted in blue) and replaces $1 (field 1 which is cntnt_id) as "tX as filler" where X is then number "1". This would then be incremented by 1 using x++ after. X shall be "2" which will be used for later if we find the next match.

if (NF==2) { $1="t"x" as filler"; print; x++ }
 
DEFINE SCHEMA Flat_File_Schema
(
cntnt_id VARCHAR(10)
);

Thanks for a detailed explanation MR.Bean

---------- Post updated at 03:57 PM ---------- Previous update was at 03:03 PM ----------

Hello,
For the second part of file.

I need the extract of file highlighted in orange.

I tried this command

awk 'BEGIN{x=1} /VALUES/,/\)\;/ {if (NF==1) { $2="as t"x"" ;print; x++ }}' brdcst_media_cntnt.tpt.ctl

The command gives me output with
(
);

I just want the highlighted text.

Can anybody help please