如何在“so”和“again”之间提取数据(第一次出现测试)
cat > sedtesting.txt
this is for testing
so test
AAgainn and again
this is for testing
so test
AAgainn and again
预期输出为:
so test
AAgainn and again
但我得到的是:
so test
AAgainn and again
so test
AAgainn and again
在下面的示例代码中,我们需要在“Exp_CDL_CONTRACT_D”和“跟踪级别”之间提取数据
以下示例代码
<TRANSFORMATION DESCRIPTION ="" NAME ="Exp_CDL_CONTRACT_D" OBJECTVERSION ="1" REUSABLE ="NO" TYPE ="Expression" VERSIONNUMBER ="15">
<TRANSFORMFIELD DATATYPE ="string" DEFAULTVALUE ="'UNKNOWN'" DESCRIPTION ="" EXPRESSION ="CONTRACT_NUM" EXPRESSIONTYPE ="GENERAL" NAME ="CONTRACT_NUM" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="120" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="string" DEFAULTVALUE ="-999" DESCRIPTION ="" EXPRESSION ="MASTER_AGREEMENT_NUM" EXPRESSIONTYPE ="GENERAL" NAME ="MASTER_AGREEMENT_NUM" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="255" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="string" DEFAULTVALUE ="" DESCRIPTION ="" EXPRESSION ="DEAL_NUM" EXPRESSIONTYPE ="GENERAL" NAME ="DEAL_NUM" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="50" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="date/time" DEFAULTVALUE ="" DESCRIPTION ="" EXPRESSION ="FUNDING_DT" EXPRESSIONTYPE ="GENERAL" NAME ="FUNDING_DT" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="29" SCALE ="9"/>
<TRANSFORMFIELD DATATYPE ="date/time" DEFAULTVALUE ="TO_DATE('1/1/1900 00:00:00 ','MM/DD/YYYY HH24:MI:SS')" DESCRIPTION ="" EXPRESSION ="BOOK_DT" EXPRESSIONTYPE ="GENERAL" NAME ="BOOK_DT" PICTURETEXT ="" PORTTYPE ="INPUT/OUTPUT" PRECISION ="29" SCALE ="9"/>
<TABLEATTRIBUTE NAME ="Tracing Level" VALUE ="Normal"/>
<TRANSFORMATION DESCRIPTION ="" NAME ="Exp_SEQ_CDL_CONTRACT_D" OBJECTVERSION ="1" REUSABLE ="NO" TYPE ="Expression" VERSIONNUMBER ="8">
<TRANSFORMFIELD DATATYPE ="decimal" DEFAULTVALUE ="" DESCRIPTION ="" EXPRESSION ="V_CNT+1" EXPRESSIONTYPE ="GENERAL" NAME ="V_CNT" PICTURETEXT ="" PORTTYPE ="LOCAL VARIABLE" PRECISION ="38" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="decimal" DEFAULTVALUE ="" DESCRIPTION ="" EXPRESSION ="IIF(V_CNT=1,:SP.GET_MAX_VALUE('CILDL.CDL_CONTRACT_D','CONTRACT_KEY'),V_MAX)" EXPRESSIONTYPE ="GENERAL" NAME ="V_MAX" PICTURETEXT ="" PORTTYPE ="LOCAL VARIABLE" PRECISION ="38" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="decimal" DEFAULTVALUE ="ERROR('transformation error')" DESCRIPTION ="" EXPRESSION ="V_CNT+V_MAX" EXPRESSIONTYPE ="GENERAL" NAME ="CONTRACT_KEY" PICTURETEXT ="" PORTTYPE ="OUTPUT" PRECISION ="38" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="decimal" DEFAULTVALUE ="" DESCRIPTION ="" EXPRESSION ="Lkp_CONTRACT_KEY" EXPRESSIONTYPE ="GENERAL" NAME =
<TABLEATTRIBUTE NAME ="Tracing Level" VALUE ="Normal"/>
<INSTANCE DESCRIPTION ="" INSTANCEID ="16" NAME ="Exp_CDL_CONTRACT_D" REUSABLE ="NO" TRANSFORMATION_NAME ="Exp_CDL_CONTRACT_D" TRANSFORMATION_TYPE ="Expression" TYPE ="TRANSFORMATION"/>
<INSTANCE DESCRIPTION ="" INSTANCEID ="17" NAME ="Lkp_CDL_CONTRACT_D" REUSABLE ="NO" TRANSFORMATION_NAME ="Lkp_CDL_CONTRACT_D" TRANSFORMATION_TYPE ="Lookup Procedure" TYPE ="TRANSFORMATION"/>
<INSTANCE DESCRIPTION ="" INSTANCEID ="18" NAME ="Rtr_CDL_CONTRACT_D" REUSABLE ="NO" TRANSFORMATION_NAME ="Rtr_CDL_CONTRACT_D"
<MAPPINGVARIABLE DATATYPE ="date/time" DEFAULTVALUE ="" DESCRIPTION ="" ISEXPRESSIONVARIABLE ="NO" ISPARAM ="YES" NAME ="$$LAST_EXTRACT_DATE" PRECISION ="29" SCALE ="9" USERDEFINED ="YES"/>
</WORKFLOW>
</FOLDER>
</REPOSITORY>
</POWERMART>
答案 0 :(得分:0)
使用awk
:
awk -F 'Exp_CDL_CONTRACT_D|Tracing Level' '{print "\"Exp_CDL_CONTRACT_D" $2 "Tracing Level\""; exit}' RS= file.xml
或grep -oP
:
grep -oP '"Exp_CDL_CONTRACT_D[\s\S]*Tracing Level"' file.xml