1

我有文本文件格式

2013-08-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPT_BU\

2013-08-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPT_BU\

2013-09-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPT_BU\

2013-09-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPT_BU\

2013-08-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPS\

2013-08-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPS\

2013-08-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPS\

2013-09-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPS\

2013-09-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPS\

2013-09-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPS\

2013-09-13 17:12:39 3868 0 status: Starting upload of U:\AOT\KPS\

我想要输出文件格式

date 2013-08-13 KPT_BU total = 2

date 2013-08-13 KPS Total = 3

date 2013-09-13 KPT_BU total = 2

date 2013-09-13 KPS total = 4
4

2 回答 2

0

我假设您希望实现以下目标:您希望计算每个日期对指定文件夹的上传次数。

我的解决方案为每个日期和路径名组合创建一个环境变量,并将一个计数器放入该变量中。它严重依赖 ENABLEDELAYEDEXPANSION,没有它我想不出解决方案,因为您不能在“for”构造中使用替代调用/%%。如果有人知道这个问题的解决方案,我会很高兴知道这一点。因此,此解决方案不适用于包含“!”的路径。由于脚本依赖于创建环境变量,因此当您用完环境内存时它将停止。

@echo off
setlocal ENABLEDELAYEDEXPANSION
:: remove all variabel starting with $ they will be restored after 'endlocal'
for /f "tokens=1 delims==" %%# in ('set $') do set "%%#="
:: create an environment variable from the date and path and increase its
:: value for every match
for /f "delims=" %%# in (testfile.txt) do (
    :: get first and last token ($1=date and $2=path) from line
    set "$1="
    for %%A in (%%#) do set $1>nul 2>nul||set "$1=%%A" & set "$2=%%A"
    :: get last part of path from $2 (mask '\' with '" "' to use in for
    set "$2="!$2:\=" "!
    for %%A in (!$2!) do set $2=%%~A
    :: generate envvar '-' must be removed, because set/a gets confused by '-'
    set "_=$!$1:-=!!$2!"
    :: counting in created vars
    if defined !_! ( set /a "!_!+=1" ) else ( set "!_!=1" ) 
)
set "$1=" & set "$2="
::output results
for /f "tokens=1,2 delims==" %%A in ('set $ 2^>nul') do (
    set _=%%A
    echo date !_:~1,4!-!_:~5,2!-!_:~7,2! !_:~8! Total = %%B
)
endlocal
goto:eof

输出略有不同,因为 'set $' 按字母顺序对变量进行排序。

于 2013-09-16T14:34:49.380 回答
0

当我运行bat文件时输出文件

++++++++++++++++++++++++++++++++++++++++++++ 日期 2013-09-11 1 总计 = 736 ----> 不使用

日期 2013-09-11 111092013_66file_B 总计 = 64

日期 2013-09-11 1KPDC 总计 = 1

日期 2013-09-11 1KPT 总计 = 1

日期 2013-09-11 1KPT_BU 总计 = 7

日期 2-01-30 0911 总计 = 1

++++++++++++++++++++++++++++++++++++++++++++++

我有完整的日志文件

http://www.4shared.com/file/eax2ykoS/filezilla.html

谢谢..

于 2013-09-17T11:49:06.387 回答