csplitです。 split
と同じですが、パターンに基づいています。 C++で
代替(試験せず):
#include <boost/shared_ptr.hpp>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
void new_output_file(boost::shared_ptr<std::ofstream> &out, const char *prefix)
{
static int i = 0;
std::ostringstream filename;
filename << prefix << "_" << i++;
out.reset(new std::ofstream(filename));
}
int main(int argc, char **argv)
{
std::ifstream in(argv[1]);
int i = 0;
long size = 0;
const long max_size = 200 * 1024 * 1024;
std::string line;
boost::shared_ptr<std::ofstream> out(NULL);
new_output_file(out, argv[2]);
while(in.good())
{
std::getline(in,line);
size += line.length() + 1 /* line termination char */;
if(size >= max_size && line.length() && line[0] == '$' && line[1] == '$')
{
new_output_file(out, argv[2]);
size = line.length() + 1;
}
out << line << std::endl;
}
return 0;
}
全く問題はないようです。 – ysth
それは確かです。分割基準として正規表現を指定することができます。質問者が/ \ $ \ $ /に設定すると、 'csplit'は彼らが望むことをするはずです。 – CanSpice
@CanSplice:目標は正規表現に分割するのではなく、\ $ \ $ \ nで区切られたチャンクを分割せずに250Mbごとに分割することです。 csplitはそれをしません。 – ysth