How to grep the desired output and output to a file?

currently I have process from a raw file to this stage

ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID")
ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID")
ALTER TABLE "EXCEL_ADMIN"."TC_TXN_ATTRIBUTE" ADD CONSTRAINT "PK_TC_TXN_ATTRIBUTE" PRIMARY KEY ("TC_TXN_ATTRIBUTE_IID")

my desired output is

@ ../../migschema/admin/pk_tc_txn_void.sql
@ ../../migschema/admin/pk_tc_txn_amt.sql
@ ../../migschema/admin/pk_tc_txn_attribute.sql

thanks

awk -F\" '{print "@ ../../migschema/admin/pk_"tolower($4)".sql"}' infile
@ ../../migschema/admin/pk_tc_txn_void.sql
@ ../../migschema/admin/pk_tc_txn_amt.sql
@ ../../migschema/admin/pk_tc_txn_attribute.sql
1 Like

hi Jotne, could you tell me that why it is $4?

thanks

better way use $6

$ awk -F\" '{print "@ ../../migschema/admin/"tolower($6)".sql"}' file
@ ../../migschema/admin/pk_tc_txn_void.sql
@ ../../migschema/admin/pk_tc_txn_amt.sql
@ ../../migschema/admin/pk_tc_txn_attribute.sql

I did use $4 since I did see needed data in that field.
Both should work fine.

input file, sqlfile_admin_package_bodies.log is now as follow


CREATE package body ACCOUNT_API is
CREATE package body BATCH_SUBSCRIPTION is
awk -F\" '{print "@ ../../migschema/admin/"tolower($3)".bdy"}' sqlfile_admin_package_bodies.log

output is now

@ ../../migschema/admin/.bdy
@ ../../migschema/admin/.bdy


is there any reason why $3 is wrong in this case?

thanks

Your input file specification seems to have changed. It does not contain double quotes, so using that field separator ( -F\" ) will not render the desired results..

sed -e 's/\([A-Z].*\)\.\(.*\) \(ADD.*\)/\@ ..\/..\/migschema\/admin\/\2/' -e 's/"//g;s/$/.sql/g' Inputfile.txt

in this case what should be used?

thanks

try

awk '{print "@ ../../migschema/admin/"tolower($4)".bdy"}' sqlfile_admin_package_bodies.log

Change your script as per your input file. Change FS and selected column.

@jediwannabe, just try leaving off -F\ " and thus use the default field separator.