Split with multiple delimiters and swap words using awk

48 Views Asked by At

How can I split string with multiple delimiters and then swap words based on few conditions -

From string - (delimiter is _ and string can vary with any kind of words, not just string starting with ocs)

'customer_document_map_ocsumm2','customer_ocsumm1','session_detail_ocsumm2'

To string -

'ocsumm2.customer_document_map'::regclass,'ocsumm1.customer'::regclass,'ocsumm2.session_detail'::regclass

I tried with my minimal knowledge on awk with below code but in vain, since I do not know how to store the results after each split and then derive back the desired result -

awk 'BEGIN {
split($0,ary,",");
for(ele in ary){
    split(ele,ary2,"_")
    owner=ary2[$NF]     
}
print owner }'
0

There are 0 best solutions below