例如:
CREATE TABLE SSS.ACTIVITY (
OWNING_ID INTEGER NOT NULL ,
ACTIVITY_TYPE FOR COLUMN ACTIV00001 VARCHAR(50) CCSID 37 NOT NULL ,
CAMPAIGN_TYPE FOR COLUMN CAMPA00001 VARCHAR(50) CCSID 37 NOT NULL ,
COMPLETED TIMESTAMP NOT NULL , "COMMENT" VARCHAR(1000) CCSID 37 DEFAULT NULL ,
FOLLOWUP_DATE FOR COLUMN FOLLO00001 DATE DEFAULT NULL ,
;
CREATE TABLE SSS.ADDRESS (
"ID" INTEGER NOT NULL ,
CITY VARCHAR(30) CCSID 37 DEFAULT NULL ,
COUNTRY VARCHAR(30) CCSID 37 DEFAULT NULL ,
ADDRESSLINE1 FOR COLUMN ADDRE00001 VARCHAR(30) CCSID 37 DEFAULT NULL ,
ADDRESSLINE2 FOR COLUMN ADDRE00002 VARCHAR(30) CCSID 37 DEFAULT NULL ,
;
在上面的例子中,有两个表。我需要输出,例如打印表名称以及包含 CCSID 单词的行。
答案1
尝试这样做awk:
$ awk '$1=="CREATE" && $2="TABLE"{table=$3} /CCSID/ && \
table{print "table " table, ":", $0}' l
输出:
table SSS.ACTIVITY : ACTIVITY_TYPE FOR COLUMN ACTIV00001 VARCHAR(50) CCSID 37 NOT NULL ,
table SSS.ACTIVITY : CAMPAIGN_TYPE FOR COLUMN CAMPA00001 VARCHAR(50) CCSID 37 NOT NULL ,
table SSS.ACTIVITY : COMPLETED TIMESTAMP NOT NULL , "COMMENT" VARCHAR(1000) CCSID 37 DEFAULT NULL ,
table SSS.ADDRESS : CITY VARCHAR(30) CCSID 37 DEFAULT NULL ,
table SSS.ADDRESS : COUNTRY VARCHAR(30) CCSID 37 DEFAULT NULL ,
table SSS.ADDRESS : ADDRESSLINE1 FOR COLUMN ADDRE00001 VARCHAR(30) CCSID 37 DEFAULT NULL ,
table SSS.ADDRESS : ADDRESSLINE2 FOR COLUMN ADDRE00002 VARCHAR(30) CCSID 37 DEFAULT NULL ,