【发布时间】:2021-04-29 19:10:05
【问题描述】:
我有一个问题,有人可以建议或给出一些 bash 脚本示例如何将数据从 file1 填充到 file2。下面是需要传输到file2的数据。
FILE1 信息
// -- ALL LINES BELOW WERE GENERATED --
// -- Some custom text that can be anywhere --
zone "domain40.com" {
type master;
file "domain4.com";
allow-transfer {
xx.xx.xx.xx;
2203:d1d0:0:4swd::1;
common-allow-transfer;
};
};
zone "domain50.com" {
type master;
file "domain5.com";
allow-transfer {
xx.xx.xx.xx;
2203:d1d0:0:4swd::1;
common-allow-transfer;
};
};
..............
FILE2 信息
zone "domain10.com" {
type master;
file "domain10.com";
allow-transfer {
xx.xx.xx.xx;
2203:d1d0:0:4swd::1;
common-allow-transfer;
};
};
zone "domain12.com" {
type master;
file "domain12.com";
allow-transfer {
xx.xx.xx.xx;
2203:d1d0:0:4swd::1;
common-allow-transfer;
};
};
zone "domain13.com" {
type master;
file "domain13.com";
allow-transfer {
xx.xx.xx.xx;
2203:d1d0:0:4swd::1;
common-allow-transfer;
};
};
..............
所以问题是如何在 linux 中合并文件,仅将数据从 FILE1 添加到 FILE2 从 zone 到 };没有任何其他文本,例如 // -- 下面的所有行都已生成 --。
我需要将该数据从导入的 FILE1 添加到现有文件 FILE2。有什么帮助吗?
【问题讨论】:
-
cat file1 file2 > file.new -
或
cat file1 >> file2将file1信息添加到file2的末尾。 -
@Barmar 是的,我知道 cat 可以做到,但问题是它会将文件 1 中的所有内容复制到文件 2 中,并带有不需要的文本。
-
那么您需要在问题中更加具体。显示示例输入和所需的结果。
-
sed -n '/startpattern/,/endpattern/p' file1 >> file2