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