Wie erstelle ich eine Batchdatei, um Text aus einer TXT-Datei in eine neue TXT-Datei einzufügen und die Aufgabe zu wiederholen?

Wie erstelle ich eine Batchdatei, um Text aus einer TXT-Datei in eine neue TXT-Datei einzufügen und die Aufgabe zu wiederholen?

wow, schlechter Titel, aber ich möchte Folgendes tun. Textdatei 1 enthält:

123.com
234.com
567.com

Ich muss diese Werte an zwei Stellen in ein neues Dokument einfügen und dann in die nächste Zeile verschieben und einfügen.

Die Ausgabedatei würde folgendermaßen aussehen

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; };
};

Sie können sehen, dass die Domäne aus der ersten Datei an zwei Stellen im Ergebnis eingefügt wird. Ich bin neu bei Batches und habe keine Ahnung, wie ich damit anfangen soll. Jede Hilfe ist wirklich willkommen.

Antwort1

Unten ist ein BashShell-Skript.

#!/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

Und eine PythonVersion für beide Linuxund Windows.

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))

Ausgabe:

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; };
                };

verwandte Informationen