中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-25 09:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [求助]抓取文件内容,有点小复杂 查看 3,172 回复 26
16 发表于 2010-10-27 10:20 ·  中国 上海 移动
新手上路
积分 12
发帖 12
注册 2010-10-21 14:34
15年会员
UID 176258
性别 男
状态 离线
人呢,要怎么弄?
17 发表于 2010-10-27 10:39 ·  中国 山东 联通
新手上路
积分 8
发帖 8
注册 2010-08-15 23:30
15年会员
UID 172436
性别 男
状态 离线
你可以这样考虑:
1、每周一抓取上周的数据,这样要比每周日抓取一次本周的数据更准确些,因为一周抓取一次,一周7天位固定的,可以一个周一的日期当前日期减7,就计算出上周一的日期来了,减1就是上周日的日期。
2、输出到当前日期的文本中,可以直接 >> %date:~0,10%.txt。
18 发表于 2010-10-27 10:47 ·  中国 上海 移动
新手上路
积分 12
发帖 12
注册 2010-10-21 14:34
15年会员
UID 176258
性别 男
状态 离线
Originally posted by dguest at 2010-10-27 10:39:
你可以这样考虑:
1、每周一抓取上周的数据,这样要比每周日抓取一次本周的数据更准确些,因为一周抓取一次,一周7天位固定的,可以一个周一的 ...



怎么算倒是小事,现在就是这两个内容怎么合并在一起,我看了下,似乎是week0和%%c之间要有个链接,但互相之间怎么赋值我不是很了解,这两个都是变量?用set连么?
19 发表于 2010-10-27 16:38 ·  中国 广东 深圳 南山区 电信
新手上路
积分 18
发帖 16
注册 2010-01-06 15:16
16年会员
UID 158100
性别 男
状态 离线
@Echo Off
set date0=%date:~0,10%
set /a year0 = %date0:~0,4%
if %date0:~4,1% == %date0:~6,1% (set month0=%date0:~5,1%) else (
set month0=%date0:~5,2%)
if %month0:~,1% == 0 set /a month0 = %month0:~-1%
if %date0:~4,1% == %date0:~-2,1% (set day0=%date0:~-1%) else (
set day0=%date0:~-2%)
if %day0:~,1% == 0 set /a day0 = %day0:~-1%
set date0=
set /a year1=%year0%%%4
set /a month1=%month0%-1
set /a month2=%month0%+1
set /a reye=(%year0%-1970+1)/4+365*(%year0%-1970)
set year0=
if %month0% LEQ 2 (set /a remo=%month0%/2+30*%month1%) else (
if %month0% LEQ 8 (
if %year1%==0 (set /a remo=%month0%/2+30*%month1%-1) else (
set /a remo=%month0%/2+30*%month1%-2)) else (
if %year1%==0 (set /a remo=%month2%/2+30*%month1%-1) else (
set /a remo=%month2%/2+30*%month1%-2)))
set year1=
set month1=
set month2=
set month0=
set /a reda=%day0%-1
set day0=
set /a re = %reye%+%remo%+%reda%-6

set /a week0 = (%reye%+%remo%+%reda%+4)%%7
if %week0% NEQ 0 echo 今天不是星期天,很抱歉!请星期天再运行! & goto end
set week0=

set reye=
set remo=
set reda=
set /a year1=(%re%%%1461)/365
set /a day0=(%re%%%1461)%%365
if %year1%==3 if %day0%==0 (set /a year1=%year1%-1 & set /a day0=365) else (set /a day0=%day0%-1)
if %year1%==4 set /a year1=%year1%-1 & set /a day0=364
set /a year0=1970+(%re%/1461)*4+%year1%
set re=

set /a month0=(%day0%)/31+1
set /a day0=%day0%%%31+1
set /a month1=%month0%-1
set /a month2=%month1%-1
if %month0% EQU 2 (if %year1%==2 (if %day0% GEQ 30 (set /a month0 = 3 & set /a day0=%day0%-29)) else (
if %day0% GEQ 29 (set /a month0 = 3 & set /a day0=%day0%-28))) else (
if %month0% GEQ 9 (if %year1%==2 (set /a day0=%day0%+%month2%/2+1) else (set /a day0=%day0%+%month2%/2+2)) else (
if %month0% GEQ 3 (if %year1%==2 (set /a day0=%day0%+%month1%/2+1) else (set /a day0=%day0%+%month1%/2+2))))
set year1=
set month1=
set month2=

set /a month3=%month0%%%2
if %month0% GTR 7 if %month3%==0 (if %day0% GEQ 32 (set /a month0=%month0%+1 & set /a day0=%day0%-31)) else (
if %day0% GEQ 31 (set /a month0=%month0%+1 & set /a day0=%day0%-30))
if %month0% GEQ 3 if %month0% LEQ 7 if %month3%==0 (if %day0% GEQ 31 (set /a month0=%month0%+1 & set /a day0=%day0%-30)) else (
if %day0% GEQ 32 (set /a month0=%month0%+1 & set /a day0=%day0%-31))
set month3=

if %month0% == %month0:~,1% set month0=0%month0%
if %day0% == %day0:~,1% set day0=0%day0%

set date0=%year0%-%month0%-%day0%
set year0=
set month0=
set day0=
echo 现在开始统计: >c:\%date:~0,10%.txt
for /f "tokens=1,2,3" %%c in (C:\OV-BLM-001_2010-10-20_16-02-20.txt) do (
if %%c GEQ %date0% if %%c LSS %date:~0,10% (echo %%c %%d %%e >>c:\%date:~0,10%.txt) & set a=a)
if defined a echo 已统计 %date0%(周一) 到 %date:~0,10%(周日) 的数据。 & set a=

set date0=

:end
pause
20 发表于 2010-11-03 16:30 ·  中国 上海 移动
新手上路
积分 12
发帖 12
注册 2010-10-21 14:34
15年会员
UID 176258
性别 男
状态 离线
感谢clinttt的大力帮助, 还有个问题想请教下, 可不可以同时对多个txt文件进行统计, 比如这句话: for /f "tokens=1,2,3" %%c in (C:\OV-BLM-001_2010-10-20_16-02-20.txt) , 如果我想同时抓取两个或两个以上文件的内容,该怎么修改呢?
21 发表于 2010-11-04 13:56 ·  中国 广东 深圳 南山区 电信
新手上路
积分 18
发帖 16
注册 2010-01-06 15:16
16年会员
UID 158100
性别 男
状态 离线
你将文件名加到 for语句的 in 后面的括号里,看是不是你想要的效果!
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
acmilanxr +1 2010-11-04 17:29
22 发表于 2010-11-04 13:57 ·  中国 广东 深圳 南山区 电信
新手上路
积分 18
发帖 16
注册 2010-01-06 15:16
16年会员
UID 158100
性别 男
状态 离线
给点分吧!
23 发表于 2010-11-04 17:31 ·  中国 上海 移动
新手上路
积分 12
发帖 12
注册 2010-10-21 14:34
15年会员
UID 176258
性别 男
状态 离线
Originally posted by clinttt at 2010-11-4 13:56:
你将文件名加到 for语句的 in 后面的括号里,看是不是你想要的效果!



不是,我意思是有大批量的那种,有没有类似 D:\路径\*.txt 这样的写法,这样就可以不用一个个列举出来了。

BTW:为啥我只能加一分
24 发表于 2010-11-04 17:47 ·  中国 广东 深圳 南山区 电信
新手上路
积分 18
发帖 16
注册 2010-01-06 15:16
16年会员
UID 158100
性别 男
状态 离线
可以使用通配符,就按你的写法就可以!
25 发表于 2010-11-05 09:31 ·  中国 上海 移动
新手上路
积分 12
发帖 12
注册 2010-10-21 14:34
15年会员
UID 176258
性别 男
状态 离线
Originally posted by clinttt at 2010-11-4 17:47:
可以使用通配符,就按你的写法就可以!



不行啊,试过了,生成的文件里面没有相关的数据存在
26 发表于 2010-11-05 10:53 ·  中国 广东 深圳 南山区 电信
新手上路
积分 18
发帖 16
注册 2010-01-06 15:16
16年会员
UID 158100
性别 男
状态 离线
for %%d in (c:\*.txt) do (
if %%~nd NEQ %date:~0,10% (
for /f "tokens=1,2,3" %%c in (%%d) do (
if %%c GEQ %date0% if %%c LSS %date:~0,10% (echo %%c %%d %%e >>c:\%date:~0,10%.txt) & set a=a)))
27 发表于 2010-12-09 10:37 ·  中国 广东 深圳 诺瓦科技发展有限公司
新手上路
积分 18
发帖 18
注册 2010-12-06 16:28
15年会员
UID 178780
性别 男
状态 离线
学习了!
论坛跳转: