.txt から新しい txt にテキストを挿入し、タスクを繰り返すバッチ ファイルを作成するにはどうすればよいですか?

.txt から新しい txt にテキストを挿入し、タスクを繰り返すバッチ ファイルを作成するにはどうすればよいですか?

うわー、タイトルは悪いですが、私がやりたいことはこれです。テキストファイル 1 には次の内容が含まれています:

123.com
234.com
567.com

これらの値を新しいドキュメントの 2 か所に挿入し、次の行に移動して挿入する必要があります。

出力ファイルは次のようになります

zone "123.com" IN {
    type master;
    file "/etc/bind/zones/db.123.com";
allow-update { none; };allow-transfer {10.10.10.10; };
};


zone "234.com" IN {
    type master;
    file "/etc/bind/zones/db.234.com";
allow-update { none; };allow-transfer {10.10.10.10; };
};


zone "567.com" IN {
    type master;
    file "/etc/bind/zones/db.567.com";
allow-update { none; };allow-transfer {10.10.10.10; };
};

最初のファイルのドメインが結果の 2 つの場所に挿入されていることがわかります。私はバッチ処理に慣れていないので、これをどのように開始すればよいかわかりません。どんな助けでも本当にありがたいです。

答え1

以下はシェルスクリプトですBash

#!/bin/bash

while read line
do
    cat <<RECORD
    zone "${line}" IN {
        type master;
            file "/etc/bind/zones/db.${line}";
        allow-update { none; };allow-transfer {10.10.10.10; };
    };

RECORD
done < Text-file-1

Pythonの両方のバージョンもあります。LinuxWindows

text = r"""
zone "%s" IN {
            type master;
                file "/etc/bind/zones/db.%s";
                allow-update { none; };allow-transfer {10.10.10.10; };
                };
"""

lines = [ x.strip() for x in open('Text-file-1').readlines() ]

for line in lines:
    print(text % (line, line))

出力:

zone "123.com" IN {
            type master;
                file "/etc/bind/zones/db.123.com";
                allow-update { none; };allow-transfer {10.10.10.10; };
                };


zone "234.com" IN {
            type master;
                file "/etc/bind/zones/db.234.com";
                allow-update { none; };allow-transfer {10.10.10.10; };
                };


zone "567.com" IN {
            type master;
                file "/etc/bind/zones/db.567.com";
                allow-update { none; };allow-transfer {10.10.10.10; };
                };

関連情報