|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『楼 主』:
[已结]echo %%i %%j 1 >>ok.txt为什么会把1丢失了呢
使用 LLM 解释/回答一下
------- 1.txt ------
154154 123 2006-9-19
4564567 321 2006-9-30
123 54 2006-10-20
for /f %%i in ('date/t') do set adate=%%i
for /f "tokens=1,2,3" %%i in (1.txt) do if %%k == %adate% echo %%i %%j 1 >>ok.txt
Last edited by HAT on 2008-10-15 at 23:48 ]
------- 1.txt ------
154154 123 2006-9-19
4564567 321 2006-9-30
123 54 2006-10-20
for /f %%i in ('date/t') do set adate=%%i
for /f "tokens=1,2,3" %%i in (1.txt) do if %%k == %adate% echo %%i %%j 1 >>ok.txt
Last edited by HAT on 2008-10-15 at 23:48 ]
|
|
2006-9-21 04:03 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
先看看你 %date/t% 是什么?
First, let's see what your %date/t% is?
|
|
2006-9-21 05:09 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
>>ok.txt echo %%i %%j 1
1>>ok.txt会把标准输出写倒ok.txt。反正 > 或 >> 前不能有数字
>>ok.txt echo %%i %%j 1
1>>ok.txt will write standard output to ok.txt. Anyway, there cannot be a number before > or >>
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-9-21 08:11 |
|
|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Originally posted by he200377 at 2006-9-21 05:09:
先看看你 %date/t% 是什么?
当前日期 设置到变量 如 adate=2006-09-20
Originally posted by he200377 at 2006-9-21 05:09:
First, take a look at what your %date/t% is?
Set the current date to a variable, such as adate=2006-09-20
|
|
2006-9-21 08:12 |
|
|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by electronixtar at 2006-9-21 08:11:
>>ok.txt echo %%i %%j 1
1>>ok.txt会把标准输出写倒ok.txt。反正 > 或 >> 前不能有数字
去了1 也不行呀
Originally posted by electronixtar at 2006-9-21 08:11:
>>ok.txt echo %%i %%j 1
Writing standard output to ok.txt with 1. Anyway, there can't be a number before > or >>
It still doesn't work after removing 1
|
|
2006-9-21 08:15 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
根据楼主1.txt的内容修改代码如下:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1-3 delims=- " %%i in ('date/t') do (
set age=%%i
set /a month=1%%j-100
set /a daily=1%%k-100
for /f "tokens=1,2,3" %%i in (1.txt) do (
if /i "%%k"=="!age!-!month!-!daily!" (
echo %%i %%j 1 >>ok.txt
)
)
)
问题出在格式上, 导致if语句判断出错不能执行重定向.
Modify the code according to the content of the original poster's 1.txt as follows:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1-3 delims=- " %%i in ('date/t') do (
set age=%%i
set /a month=1%%j-100
set /a daily=1%%k-100
for /f "tokens=1,2,3" %%a in (1.txt) do (
if /i "%%c"=="!age!-!month!-!daily!" (
echo %%a %%b 1 >>ok.txt
)
)
)
The problem lies in the format, resulting in the if statement judgment being incorrect and unable to perform the redirection.
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-21 09:09 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
%date%的格式是 2006-09-19,而非1.txt中的2006-9-19,所以,你的代码中,if语句无论如何都不能成立;
另外,echo %%i %%j 1 >>ok.txt的格式是错误的,最后的1被CMD认为是句柄值,会导致没有任何内容输入到ok.txt。electronixtar 在『第 3 楼』所说的:> 或 >> 前不能有数字 一句是不够准确的,准确的说法是:如果echo最后一列的数字是0~9中的任何一个数字,将不会把内容写入ok.txt中。
The format of %date% is 2006-09-19, not 2006-9-19 in 1.txt. So, in your code, the if statement will never hold true in any case.
Also, the format of echo %%i %%j 1 >>ok.txt is incorrect. The final 1 is regarded as a handle value by CMD, which will result in no content being input into ok.txt. What electronixtar said in "Post #3" that "there cannot be a number before >>" is not precise enough. The accurate statement is: If the last column of the echo is any number from 0 to 9, no content will be written into ok.txt.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-21 09:15 |
|
|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
|
2006-9-21 09:15 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
另外,echo %%i %%j 1 >>ok.txt的格式是错误 ... [/quote]
好像并没有飞扬兄说的这种错误, 如果0-9是单独的将会认为是句柄, 而这个重定向前跟了几个值, 所以不会出现兄所说的这种情况!
In addition, the format of echo %%i %%j 1 >>ok.txt is incorrect...
It seems that there is no such error as Brother Feiyang said. If 0-9 are single, they will be regarded as handles, but there are several values before this redirection, so the situation you mentioned will not occur!
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-21 09:22 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
我所说的错误,并非执行的时候会出错,而是说写到ok.txt中的内容并非你想要的完整内容,比如,你可以运行语句 echo 123 1>ok.txt 试试,在ok.txt中并不是你想要的 123 1,而是 123,少了最后一列的数字1。
The error I'm talking about isn't that it goes wrong when executed, but that the content written into ok.txt isn't the complete content you want. For example, you can run the statement echo 123 1>ok.txt and try it. In ok.txt, it's not the 123 1 you want, but just 123, missing the last column of the number 1.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-21 09:29 |
|
|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
多试过1 后加一个空格可以解决
Try adding a space after 1 more times can solve it
|
|
2006-9-21 09:30 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
呵呵~ namejm兄说的对.
楼主的后面加空格解决了无法重定向问题...
Hehe~ Brother namejm is right.
The problem of unable to redirect is solved by adding a space after the楼主...
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-21 09:33 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
如果要求不是太苛刻的话,是可以在最后一列的数字后加个空格来避免CMD的识别问题,但是,如果要求非常苛刻的话,比如要求最后一列数字的0~9写到文本中之后,后面不带空格的话,就应该对echo语句作一些处理,换成下列写法中的任意一种:
1、(echo 内容)>test.txt
2、>test.txt echo 内容
另外,还可以用 echo ^内容>test.txt的格式,但是这个写法有很大的局限性,即转义符^只能加在内容最后一列的单个的0~9前面,如果是 echo ^123 1>test.txt 的写法,还是不成,要写成 echo 123 ^1>test.txt才可以。
If the requirements are not too strict, you can add a space after the number in the last column to avoid CMD recognition problems. However, if the requirements are very strict, such as requiring that the numbers 0-9 in the last column be written into the text without a space after them, some processing should be done on the echo statement, and any of the following forms should be used:
1、(echo content)>test.txt
2、>test.txt echo content
In addition, you can also use the format echo ^content>test.txt, but this form has great limitations, that is, the escape character ^ can only be added in front of a single 0-9 in the last column. If it is the writing of echo ^123 1>test.txt, it is still not working. It should be written as echo 123 ^1>test.txt.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-21 09:47 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
是的, 出现这种情况尽量用字符转义...
Yes, when this situation occurs, try to use character escaping...
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-21 09:49 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
可以用 "" 来转义——在ntcmds.chm上看到的
Can be escaped with "" - seen on ntcmds.chm
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-9-21 10:35 |
|