使用 awk。
printf
版本_
cat tst.awk
输出
{
printf "set security zones security-zone 1 address-book address H-%s %s/32 -\nset security zones security-zone 1 address-book address-set GROUP address H-%s\n", $0, $0, $0
}
print
版本。
{
message = "set security zones security-zone 1 address-book address"
print message, "H-" $0, $0 "/32", "-"
print message "-set", "GROUP", "address", "H-" $0
}
文件
cat file.txt
输出
1.1.1.1
2.2.2.2
3.3.3.3
跑
awk -f tst.awk file.txt > out.txt
查看 out.txt
cat out.txt
输出
set security zones security-zone 1 address-book address H-1.1.1.1 1.1.1.1/32 -
set security zones security-zone 1 address-book address-set GROUP address H-1.1.1.1
set security zones security-zone 1 address-book address H-2.2.2.2 2.2.2.2/32 -
set security zones security-zone 1 address-book address-set GROUP address H-2.2.2.2
set security zones security-zone 1 address-book address H-3.3.3.3 3.3.3.3/32 -
set security zones security-zone 1 address-book address-set GROUP address H-3.3.3.3