对于 Perl,您可以使用Tie::File轻松完成。
#!/usr/bin/env perl
use utf8;
use v5.12;
use strict;
use warnings;
use warnings qw(FATAL utf8);
use open qw(:std :utf8);
use Tie::File;
for my $arg (@ARGV) {
# Skip to the next one unless the current $arg is a file.
next unless -f $arg;
# Added benefit: No such thing as a file being too big
tie my @file, 'Tie::File', $arg or die;
# New first line, will become the second line
unshift @file, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
# The real first line.
unshift @file, '<?xml version="1.0" encoding="UTF-8"?>';
# Final line.
push @file, '</urlset>';
# All done.
untie @file;
}
保存到您想要的任何内容,然后将其运行为perl whatever_you_named_it path/to/files/*
.