中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-29 08:05
47,816 topics / 349,916 posts / today 0 new / 48,265 members
DOS批处理 & 脚本技术(批处理室) » Split a larger text with a certain regular pattern into multiple smaller text files?
Printable Version  1,294 / 5
Floor1 zzhh612 Posted 2007-03-29 08:25
中级用户 Posts 103 Credits 278
I have a relatively large text as follows:
//@Function name: abs
//Function prototype: int abs(int x);
//Function purpose: find the absolute value of integer x
//Function return: calculation result
//Parameter description:
//Header file: <math.h>,<stdlib.h>
//Usage example:
#include <stdio.h>
#include <math.h>
int main()
{
int number=-1234;
printf("number: %d absolute value: %d",number,abs(number));
return 0;
}


//@Function name: fabs
//Function prototype: double fabs(double x);
//Function purpose: find the absolute value of x.
//Function return: calculation result
//Parameter description:
//Header file: <math.h>
//Usage example:
#include <stdio.h>
#include <math.h>
int main()
{
float number=-1234.0;
printf("number: %f absolute value: %f",number,fabs(number));
return 0;
}




//@Function name: sin
//Function prototype: double sin(double x);
//Function purpose: calculate the value of sinx. Sine function
//Function return: calculation result
//Parameter description: the unit is radians
//Header file: <math.h>
//Usage example:
#include <stdio.h>
#include <math.h>
int main()
{
double result,x=0.5;
result=sin(x);
printf("The sin() of %lf is %lf",x,result);
return 0;
}
.........

I want to use the text before each "//@Function name" as the boundary, and split each C-language function description into a separate text file named after the function name.
Since there are quite a lot of them, I want to do it with a batch file, but I don't know how to start. Hope an expert can give me some pointers?

[ Last edited by zzhh612 on 2007-3-29 at 09:49 AM ]
Floor2 jmz573515 Posted 2007-03-29 12:01
银牌会员 Posts 464 Credits 1,212
Floor3 zzhh612 Posted 2007-03-29 14:54
中级用户 Posts 103 Credits 278
The VBScript from the poster above is pretty good. I tried it, and it works. But I wonder whether this kind of thing can be done with a DOS batch file. DOS is more fundamental, and I want to learn through actually using it. Thanks.

[ Last edited by zzhh612 on 2007-3-29 at 03:03 PM ]
Floor4 ccwan Posted 2007-03-29 23:52
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊

The format is changed slightly, mainly the spaces.
Floor5 ccwan Posted 2007-03-30 03:01
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Posting the code written by brother 9527 on his behalf; it matches the code format the OP wants very well.
Floor6 zzhh612 Posted 2007-03-30 10:01
中级用户 Posts 103 Credits 278
The code from jmz573515 and the code posted on behalf of ccwan achieved the same effect.
Really different tunes played with equal skill. Looks like I still have a long way to go in learning: "The road ahead is long and has no ending; yet high and low I will search with my will unbending...
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023