Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

727.Advanced search and replace -- How to save specified lines of text file into different files?

User: park -- 2011-02-27          << 726  728 >>
Hits: 418
Type: Advanced search and replace   
Search all Advanced search and replace examples
Description:
How to delete just one line of one file each time and save the line-deleted file
to a new name,in a loop from the maximum line to the zero line?
Input Sample:
A file,line number is m,like the below
m is 5,each time delete just line and
save the line-deleted file to a new
file.file name is the line
number__4.txt.....1.txt,0.txt.
A.txt
2007/01/11,4.38,4.42,4.28,4.42,2442496
.00,0.00
2007/01/12,4.42,4.64,4.40,4.41,4820221
.00,0.00
2007/01/15,4.26,4.63,4.26,4.58,1827455
.00,0.00
2007/01/16,4.53,4.68,4.53,4.65,1550442
.00,0.00
2007/01/17,4.63,4.69,4.42,4.56,2655067
.00,0.00
Output Sample:
4.txt
2007/01/11,4.38,4.42,4.28,4.42,2442496
.00,0.00
2007/01/12,4.42,4.64,4.40,4.41,4820221
.00,0.00
2007/01/15,4.26,4.63,4.26,4.58,1827455
.00,0.00
2007/01/16,4.53,4.68,4.53,4.65,1550442
.00,0.00
3.txt
2007/01/11,4.38,4.42,4.28,4.42,2442496
.00,0.00
2007/01/12,4.42,4.64,4.40,4.41,4820221
.00,0.00
2007/01/15,4.26,4.63,4.26,4.58,1827455
.00,0.00
2.txt
2007/01/11,4.38,4.42,4.28,4.42,2442496
.00,0.00
2007/01/12,4.42,4.64,4.40,4.41,4820221
.00,0.00
............
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
Assume the target file m.txt need to write to d:\test folder:
1. ctrl-o open source text file
2. ctrl-h open 'replace' window
* click 'advanced' page, copy following code into 'Run following for each matched unit' entry:

3. click 'Replace', check folder "d:\test\", there should be files 1.txt, 2.txt,... m.txt

Note: 
* the folder d:\test\ should be created in advance.
* use double backslash in the code like d:\\test\\

Screenshot 1:  Replace_Advanced_Window


Similar Examples:
How to remove duplicate lines in multiple files in different sub-folders? (66%)
How to extract specified lines in multiple excel(csv) files? (65%)
How to shuffle specified lines in multiple text files? (65%)
How to batch extract specified lines from a text file? (65%)
How to replace the same words in text files with different strings? (63%)
How to search specified pattern in a text file and remove spaces in it? (62%)
How to split a text file into multiple files evenly on size? (60%)
How to sort all the lines of a text file by order the multiple columns? (60%)

Check Demo of Advanced search and replace
Keywords:
loop  maximum  slash  backslash  double  coding  encoding  max  encod  create  for loop  delete code  copy files different  write lines  delete specified  copy files from a text file  delete folder  copy lines