问题
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