I have a specified set of string with some keywords to match.
我有一组指定的字符串,其中包含一些要匹配的关键字。
Key words are : string will contain "CREATESETTABLE" and dot(.) and TABLENAME In below sample string, DATABASE1 and DATABASE2 are dynamic but after that a dot(.) will come then followed by TABLENAME; but dot(.) and TABLENAME may repeat n times.
关键词是:字符串将包含“CREATESETTABLE”和点(。)和TABLENAME在下面的示例字符串中,DATABASE1和DATABASE2是动态的,但之后将出现一个点(。),然后是TABLENAME;但是点(。)和TABLENAME可能会重复n次。
string="CREATESETTABLEDATABASE1.TABLE1(uid)CREATESETTABLEDATABASE1.TABLENAMEuid,cid,mid)DATABASE2.TABLENAME(hi,hello)"
字符串= “CREATESETTABLEDATABASE1.TABLE1(UID)CREATESETTABLEDATABASE1.TABLENAMEuid,CID,MID)DATABASE2.TABLENAME(HI,你好)”
What i used is :
我用的是:
echo "$string" | awk -F'CREATESETTABLE+[^ ]+.TABLENAME' '{print $2}'
Actual out put is : (hi,hello)
实际出局是:(嗨,你好)
Expected out put is: uid,cid,mid)DATABASE.TABLENAME(hi,hello)
预期输出是:uid,cid,mid)DATABASE.TABLENAME(嗨,你好)
Note: Use the keywords which i specified in this example. Dont use other keywords such as "(" ; other data are dynamic only what i said is static
注意:使用我在此示例中指定的关键字。不要使用其他关键字,如“(”;其他数据只是动态的,我说的是静态的
1 个解决方案
#1
1
Try this sed
,
试试这个sed,
echo $string | sed 's/.*CREATESETTABLE[^)]\+TABLENAME\(.*\)/\1/g'
As mentioned in comments,
如评论中所述,
sed -e 's/.*CREATESETTABLE[^)]\+TABLENAME\(.*\)/\1/g' -e 's/.*CREATEMULTISETTABLE[^)]\+TABLENAME\(.*\)/\1/g'
#1
1
Try this sed
,
试试这个sed,
echo $string | sed 's/.*CREATESETTABLE[^)]\+TABLENAME\(.*\)/\1/g'
As mentioned in comments,
如评论中所述,
sed -e 's/.*CREATESETTABLE[^)]\+TABLENAME\(.*\)/\1/g' -e 's/.*CREATEMULTISETTABLE[^)]\+TABLENAME\(.*\)/\1/g'