Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用增量序列和名称字段在单个文件中多次复制模板,并从其他文件复制_Linux_Bash_Awk_Sed_Copy - Fatal编程技术网

Linux 使用增量序列和名称字段在单个文件中多次复制模板,并从其他文件复制

Linux 使用增量序列和名称字段在单个文件中多次复制模板,并从其他文件复制,linux,bash,awk,sed,copy,Linux,Bash,Awk,Sed,Copy,我有一个占位符规则,我需要用增量序列复制它 根据“国家”名称进一步需要从另一个文件复制到单个文件中 # 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

我有一个占位符规则,我需要用增量序列复制它 根据“国家”名称进一步需要从另一个文件复制到单个文件中

# 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
}
**规则集S_ID和规则S_ID_R1的序列ID需要相同

为了复制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
}
像这样的

awk '{ print "Rule_set S_" NR "\n{\n RuleS_" NR "_R1\n    Conditions " \
       "ADDR in " $0 "\n    Actions   Invoice to bill\n}\n" }' country
像这样的

awk '{ print "Rule_set S_" NR "\n{\n RuleS_" NR "_R1\n    Conditions " \
       "ADDR in " $0 "\n    Actions   Invoice to bill\n}\n" }' country

@塞勒斯,谢谢mate@cyrus感谢mateI,我计划插值,但最终没有这样做;我同意,
print
在这里更有意义;我同意,
print
在这里更有意义。