我有一个 457 MB 的文件,并试图将其拆分为更小的文件。这是目前的工作:
csplit -z Scan.nessus /\<ReportHost/ '{*}'
但是,这为我创建了大约 61.5k,因为我在这个 457MB 文件中有大量这些条目。最终,我可能会按每 50 个条目而不是每个条目来分解它。
有没有办法修改它来实现这一点?我在某种程度上尝试在 Ruby 中执行此操作,但尝试使用 Nokogiri 解析文件时似乎最大化了 VM 的内存。
怎么perl
解决?
即使你不熟悉 的语法,修改定义为等perl
的参数自定义它也不难
。my $pattern = ...
#!/bin/bash
perl -e '
use strict; use warnings;
my $pattern = "<ReportHost"; # the pattern to split
my $prefix = "xx"; # prefix of the output file
my $n = 50; # number of entries per file
my $filename = $prefix . "000";
my $count = 0;
while (<>) {
if (/$pattern/o) { # if the pattern is found
if ($count % $n == 0) { # open the new file to output
open(FH, "> $filename") or die "$filename";
$filename++; # increment the number of the file
}
$count++;
}
print FH; # print the line to the opened file
}
' Scan.nessus # input filename