![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-12 09:56 |
共 47,811 主题排行 / 349,897 发帖 / 今日 0 篇 / 48,256 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » [求助]抓取文件内容,有点小复杂 |
| 可打印版本 3,459 / 26 |
| 第16楼 acmilanxr | 发表于 2010-10-27 10:20 |
| 新手上路 发帖 12 积分 12 | |
|
人呢,要怎么弄?
|
|
| 第17楼 dguest | 发表于 2010-10-27 10:39 |
| 新手上路 发帖 8 积分 8 | |
|
你可以这样考虑:
1、每周一抓取上周的数据,这样要比每周日抓取一次本周的数据更准确些,因为一周抓取一次,一周7天位固定的,可以一个周一的日期当前日期减7,就计算出上周一的日期来了,减1就是上周日的日期。 2、输出到当前日期的文本中,可以直接 >> %date:~0,10%.txt。 |
|
| 第18楼 acmilanxr | 发表于 2010-10-27 10:47 |
| 新手上路 发帖 12 积分 12 | |
Originally posted by dguest at 2010-10-27 10:39: 怎么算倒是小事,现在就是这两个内容怎么合并在一起,我看了下,似乎是week0和%%c之间要有个链接,但互相之间怎么赋值我不是很了解,这两个都是变量?用set连么? |
|
| 第19楼 clinttt | 发表于 2010-10-27 16:38 |
| 新手上路 发帖 16 积分 18 | |
|
@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楼 acmilanxr | 发表于 2010-11-03 16:30 |
| 新手上路 发帖 12 积分 12 | |
|
感谢clinttt的大力帮助, 还有个问题想请教下, 可不可以同时对多个txt文件进行统计, 比如这句话: for /f "tokens=1,2,3" %%c in (C:\OV-BLM-001_2010-10-20_16-02-20.txt) , 如果我想同时抓取两个或两个以上文件的内容,该怎么修改呢?
|
|
| 第21楼 clinttt | 发表于 2010-11-04 13:56 |
| 新手上路 发帖 16 积分 18 | |
|
你将文件名加到 for语句的 in 后面的括号里,看是不是你想要的效果!
|
|
| 第22楼 clinttt | 发表于 2010-11-04 13:57 |
| 新手上路 发帖 16 积分 18 | |
|
给点分吧!
|
|
| 第23楼 acmilanxr | 发表于 2010-11-04 17:31 |
| 新手上路 发帖 12 积分 12 | |
Originally posted by clinttt at 2010-11-4 13:56: 不是,我意思是有大批量的那种,有没有类似 D:\路径\*.txt 这样的写法,这样就可以不用一个个列举出来了。 BTW:为啥我只能加一分 |
|
| 第24楼 clinttt | 发表于 2010-11-04 17:47 |
| 新手上路 发帖 16 积分 18 | |
|
可以使用通配符,就按你的写法就可以!
|
|
| 第25楼 acmilanxr | 发表于 2010-11-05 09:31 |
| 新手上路 发帖 12 积分 12 | |
Originally posted by clinttt at 2010-11-4 17:47: 不行啊,试过了,生成的文件里面没有相关的数据存在 |
|
| 第26楼 clinttt | 发表于 2010-11-05 10:53 |
| 新手上路 发帖 16 积分 18 | |
|
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楼 yf6122010 | 发表于 2010-12-09 10:37 |
| 新手上路 发帖 18 积分 18 | |
|
学习了!
|
|
| 上一页 1 2 |
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |