在递归括号之间提取数据

时间:2018-01-20 12:02:40

标签: regex perl unix awk sed

任何人都可以帮我在linux上“(”和“)”之间提取文本。 PS - 在数据之间还包含括号()。

文字:

CREATE SET TABLE xxxxx.xxxxxx ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (

     aflt_type_cd CHAR(1) CHARACTER SET LATIN UPPERCASE NOT CASESPECIFIC TITLE 'AFFILIATE TYPE CODE',
      aflt_co_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'AFFILIATE COMPANY CODE',
      cris_ind CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'CUSTOMER RECORDS INFORMATION SYSTEM INDICATOR',
      cabs_ind CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'CARRIER ACCESS BILLING SYSTEM INDICATOR',
      src_feed_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'SOURCE FEED CODE',
      intgt_ind CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'INTEGRATED INDICATOR' NOT NULL,
      lst_updt_by CHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'LAST UPDATED BY' NOT NULL,
      load_dt_tm TIMESTAMP(6) TITLE 'LOAD DATE TIME' NOT NULL,
      updt_dt_tm TIMESTAMP(6) TITLE 'UPDATE DATE TIME' NOT NULL)
PRIMARY INDEX nupi_bill_sys ( bill_sys_geo_id );

所需文字:

aflt_type_cd CHAR(1) CHARACTER SET LATIN UPPERCASE NOT CASESPECIFIC TITLE 'AFFILIATE TYPE CODE',
      aflt_co_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'AFFILIATE COMPANY CODE',
      cris_ind CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'CUSTOMER RECORDS INFORMATION SYSTEM INDICATOR',
      cabs_ind CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'CARRIER ACCESS BILLING SYSTEM INDICATOR',
      src_feed_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'SOURCE FEED CODE',
      intgt_ind CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'INTEGRATED INDICATOR' NOT NULL,
      lst_updt_by CHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC TITLE 'LAST UPDATED BY' NOT NULL,
      load_dt_tm TIMESTAMP(6) TITLE 'LOAD DATE TIME' NOT NULL,
      updt_dt_tm TIMESTAMP(6) TITLE 'UPDATE DATE TIME' NOT NULL

提前致谢.. !! :)

2 个答案:

答案 0 :(得分:0)

在Perl中尝试此选项:

$text = "CREATE SET TABLE xxxx.xxxx ( CONTENT )";
if ($text =~ /CREATE SET TABLE [^(]* \(([^)]*)\)/) {
    print $1;
}

这输出CONTENT,q.v。下面的演示。

Demo

答案 1 :(得分:-1)

{{1}}