对于这个简单的问题,我对Perl非常抱歉。
我有一个Perl脚本,它生成7个csv文件。所有这些文件都有8个常见的列标题。
文件名将是常量的,每个文件只有8列,并且每个列的每个值中总是有数据。
每个文件的大小从来不超过400 K。
我希望使用Perl将这些csv文件组合成一个文件。输出将具有相同的列标题和来自所有7个文件的数据。
发布于 2013-08-01 13:16:08
如果您使用的是某种Unix,则可以使用tail
。
$ tail -qn +2 fileA fileB ...
-q
在输出中抑制文件名;-n +2
用第2行启动输出。
要获得标题,还需要:
$ (head -n 1 fileA; tail -qn +2 fileA fileB ...) > output-file
如果您需要使用Perl:
use strict; use warnings; use autodie;
my $files = $#ARGV; # get number of files - 1
while (my $file = shift @ARGV) {
open my $fh, "<", $file;
<$fh> unless $files == @ARGV; # discard header unless first file
print while <$fh>; # output the rest
}
然后:$ perl the-script.pl fileA fileB ...
https://stackoverflow.com/questions/17993919
复制相似问题