Frage

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)

War es hilfreich?

Lösung

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top