awk -F not finding strings if AND condition is used

佐手、 提交于 2020-01-06 17:59:55

问题


I need to print second part of the searched string

a="Hello I have a CREATE set TABLE as (uid, cid, mid)"

Above string may continue as long as it needs.

echo "$a" | awk -F"/CREATE/&&/TABLE/" '{print $2}'

it returns nothing...

It should return:

as (uid, cid,mid)


回答1:


Try this:

echo "$a" | awk -F"CREATE.*TABLE" '{print $2}'
 as (uid, cid, mid)

Not sure if regex in Field Separator do work.


Using variable Field Separators:

sep=two
echo "_one_two_three_four" | awk -v var=$sep '{split($0,a,"_"var);print a[2]}'
_three_four

sep=three
echo "_one_two_three_four" | awk -v var=$sep '{split($0,a,"_"var);print a[2]}'
_four


来源:https://stackoverflow.com/questions/22381403/awk-f-not-finding-strings-if-and-condition-is-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!