unix - sed search and replace a string with its sub string value -


i have create table script ( external table). want replace table name ext_[first 27 characters of original table]

sample i/p file

create table "p12345678912345678912345678912" (   "partition_key" varchar2(12),   "id" varchar2(100),   "stress_testing_scenario_id" varchar2(100),   "tranche_collateral_type" varchar2(20),   "tranche_guarantee_type" varchar2(20),   "bs_type" varchar2(3),   "contract_reference" varchar2(50), 

expected o/p

create table "ext_p12345678912345678912345678" (   "partition_key" varchar2(12),   "id" varchar2(100),   "stress_testing_scenario_id" varchar2(100),   "tranche_collateral_type" varchar2(20),   "tranche_guarantee_type" varchar2(20),   "bs_type" varchar2(3),   "contract_reference" varchar2(50), 

the script needs work on both linux , solaris.

this awk one-liner works example:

awk -f'"' -v ofs='"' '/create table/{$2=substr($2,1,27);sub("^","ext_",$2)}7' file 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -