China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 11:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Grabbing file content, a bit complicated View 3,176 Replies 26
Floor 16 Posted 2010-10-27 10:20 ·  中国 上海 移动
新手上路
Credits 12
Posts 12
Joined 2010-10-21 14:34
15-year member
UID 176258
Gender Male
Status Offline
Where are people? How to do it?
Floor 17 Posted 2010-10-27 10:39 ·  中国 山东 联通
新手上路
Credits 8
Posts 8
Joined 2010-08-15 23:30
15-year member
UID 172436
Gender Male
Status Offline
You can consider it this way:
1. Grab the data of the previous week every Monday. This is more accurate than grabbing the data of this week once every Sunday. Because grabbing once a week, the 7 days of a week are fixed. You can subtract 7 from the current date to calculate the date of last Monday, and subtract 1 to get the date of last Sunday.
2. When outputting to the text of the current date, you can directly >> %date:~0,10%.txt.
Floor 18 Posted 2010-10-27 10:47 ·  中国 上海 移动
新手上路
Credits 12
Posts 12
Joined 2010-10-21 14:34
15-year member
UID 176258
Gender Male
Status Offline
How to calculate is a minor matter. Now the main thing is how to combine these two contents. I took a look and it seems there should be a link between week0 and %%c, but I don't know much about how to assign values to each other. Are both of these variables? Should I use set to connect them?
Floor 19 Posted 2010-10-27 16:38 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 18
Posts 16
Joined 2010-01-06 15:16
16-year member
UID 158100
Gender Male
Status Offline
@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 Today is not Sunday, sorry! Please run it on Sunday! & 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 Now start statistics: >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 Data from %date0% (Monday) to %date:~0,10% (Sunday) has been counted. & set a=

set date0=

:end
pause
Floor 20 Posted 2010-11-03 16:30 ·  中国 上海 移动
新手上路
Credits 12
Posts 12
Joined 2010-10-21 14:34
15-year member
UID 176258
Gender Male
Status Offline
Thanks to clinttt's great help, there is another question I want to ask. Can I count multiple txt files at the same time? For example, this sentence: for /f "tokens=1,2,3" %%c in (C:\OV-BLM-001_2010-10-20_16-02-20.txt), if I want to capture the contents of two or more files at the same time, how to modify it?
Floor 21 Posted 2010-11-04 13:56 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 18
Posts 16
Joined 2010-01-06 15:16
16-year member
UID 158100
Gender Male
Status Offline
Add the file name to the parentheses after in in the for statement, and see if it's the effect you want!
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
acmilanxr +1 2010-11-04 17:29
Floor 22 Posted 2010-11-04 13:57 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 18
Posts 16
Joined 2010-01-06 15:16
16-year member
UID 158100
Gender Male
Status Offline
Floor 23 Posted 2010-11-04 17:31 ·  中国 上海 移动
新手上路
Credits 12
Posts 12
Joined 2010-10-21 14:34
15-year member
UID 176258
Gender Male
Status Offline
Originally posted by clinttt at 2010-11-4 13:56:
You add the file name after the in parentheses in the for statement, see if it is the effect you want!



No, I mean there are a large number of such, is there a writing like D:\path\*.txt, so you don't have to list them one by one.

BTW: Why can I only add one point
Floor 24 Posted 2010-11-04 17:47 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 18
Posts 16
Joined 2010-01-06 15:16
16-year member
UID 158100
Gender Male
Status Offline
Wildcards can be used, just follow your writing!
Floor 25 Posted 2010-11-05 09:31 ·  中国 上海 移动
新手上路
Credits 12
Posts 12
Joined 2010-10-21 14:34
15-year member
UID 176258
Gender Male
Status Offline
Originally posted by clinttt at 2010-11-4 17:47:
Wildcards can be used, just write it as you did!



It doesn't work. I tried it, but there is no relevant data in the generated file.
Floor 26 Posted 2010-11-05 10:53 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 18
Posts 16
Joined 2010-01-06 15:16
16-year member
UID 158100
Gender Male
Status Offline
```batch
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)))
```
Floor 27 Posted 2010-12-09 10:37 ·  中国 广东 深圳 诺瓦科技发展有限公司
新手上路
Credits 18
Posts 18
Joined 2010-12-06 16:28
15-year member
UID 178780
Gender Male
Status Offline
Learning
Forum Jump: