Board logo

标题: 请问批处理可以按要求拆分多个文本文件吗 [打印本页]

作者: 88xi     时间: 2007-10-15 13:07    标题: 请问批处理可以按要求拆分多个文本文件吗

我想把一个文件夹下多个文本,按30行来拆分,并保存在指定的文件夹里,并用原文件名命名。
比如:文件夹里有a.txt、b.txt、c.txt....把他们按30行来分割,保存在d:\wj里,并命名为a1.txt、a2.txt、a3.txt....b1.txt、b2.txt...c1.txt、c2.txt....如何实现?
作者: lxmxn     时间: 2007-10-15 15:54
a.txt 按30行一个文件拆分为a1.txt、a2.txt、a3.txt ?
作者: 88xi     时间: 2007-10-15 16:37
是的
作者: Auto     时间: 2007-12-25 20:10
我也想知道这个...
要是能按分章节拆分的话更好...
作者: zerocq     时间: 2007-12-25 20:57
Usage: split.exe [OPTION] [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
PREFIX is `x'.  With no INPUT, or when INPUT is -, read standard input.

  -b, --bytes=SIZE        put SIZE bytes per output file
  -C, --line-bytes=SIZE   put at most SIZE bytes of lines per output file
  -l, --lines=NUMBER      put NUMBER lines per output file
  -NUMBER                 same as -l NUMBER
      --verbose           print a diagnostic to standard error just
                            before each output file is opened
      --help              display this help and exit
      --version           output version information and exit

SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.

Report bugs to <bug-textutils@gnu.org>.


附件无法上传.咋办
作者: HAT     时间: 2007-12-25 21:57
google搜索“UnxUtils”
里面有split
作者: terse     时间: 2007-12-25 22:07
能满足否?

  Quote:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b /a-d "*.txt" 2^>nul') do (
        set id=1
        set num=
        for /f "tokens=1,* delims=:" %%a in ('findstr /n .* "%%i"') do (      
        set/A num+=1
echo/%%b>>"d:\wj\%%~ni!id!.txt"
if !num! GEQ 30 set/A id+=1&set num=
)
)
pause


作者: everest79     时间: 2007-12-25 22:10
通过for计数输出会忽略空行,原来讨论过这个问题,好像没办法,否则代码太烦琐,过大文本太慢
作者: everest79     时间: 2007-12-25 22:55
找到一个方法
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('dir /b *.txt') do (
    for /f "skip=2 tokens=1* delims=[]" %%b in ('find /v /n "" "%%a"') do (
        set /a num=%%b/30+1
        echo.%%c>>"%%~dpna!num!%%~xa"
    )
set num=
)