输入master_table_list.txt(由|分隔的样本单个记录)
hub_business_partner|`hash_business_partner` string COMMENT 'Surrogate Key for Business Partner', `key_business_partner` string COMMENT 'Business Key for Business Partner', `rec_srce` string COMMENT 'Record Source'|`rec_date` timestamp|key_business_partner|rec_date|COMMENT 'Business Partner Hub'|customer
insert_table_preparation.txt中需要输出
customer|hub_business_partner|hash_business_partner,key_business_partner,rec_srce,rec_date
使用的代码
echo $line | awk -F'|' '{printf("'%s'\n",);}' | grep -o '`.*`'| tr -d '``' >>insert_table_preparation.txt
请帮我提取至少第二个字段(字段列表)。
提前致谢。
此致 马洛
答案 0 :(得分:0)
这是一个快速而又脏的响应,但这会读取您的示例输入行并生成示例输出:
echo $line | sed -e "s/ string COMMENT[^,|]*//g" -e "s/\`//g" -e "s/, /,/g" | awk 'BEGIN{ FS = "|"; OFS = "" } { split($2, foo, ","); print $7, "|", $1, "|", foo[1], ",", foo[2], ",", foo[3], "|", $5 }'