我有一个占位符规则,我需要用增量序列复制它 根据“country”名称,进一步需要从单个文件中的另一个文件复制。
# Cat country
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda
Argentina
Armenia
此文件包含195个条目& b / w行没有空格,每个条目都在一个新行中。这些条目不是固定的,有时可能是10或100.
# cat rule
Rule_set S_1
{
Rule S_1_R1
Conditions ADDR in country
Actions Invoice to bill
}
** Rule_Set的序列ID S_ID&规则S_ID_R1需要相同。
要复制100次,我已经使用了它。
for i in {1..100}; do cat rule >> file2; done
顺序
awk -vRS=S_1 '{$0=n$0;ORS=RT}++n' file2 > new_rule
但是排序在一条规则中给了我不同的ID,我仍然不知道用国家列表替换国家/地区字符串。
预期输出
Rule_set S_1
{
Rule S_1_R1
Conditions ADDR in Afghanistan
Actions Invoice to bill
}
Rule_set S_2
{
Rule S_2_R1
Conditions ADDR in Albania
Actions Invoice to bill
}
.
.
.
.
Rule_set S_195
{
Rule S_195_R1
Conditions ADDR in Zimbabwe
Actions Invoice to bill
}
答案 0 :(得分:2)
这样的东西?
awk '{ print "Rule_set S_" NR "\n{\n RuleS_" NR "_R1\n Conditions " \
"ADDR in " $0 "\n Actions Invoice to bill\n}\n" }' country