|  | 
 
| van416 初级用户
 
   
 
 
 
 积分 34
 发帖 30
 注册 2010-12-2
 状态 离线
 | 
| 『楼 主』:
 FOR循環與findstr怎么合并??
 
使用 LLM 解释/回答一下 
 
 
今天在做FOR語句不知道該如何將for語句與findstr合并,以下為分開的程式,請幫忙看看,感謝~
 需求:將project字段后的內容取出
 
 2.ini
 Hierarchy ID          : Normal Board
 Chip SKU              : 250
 Project               : 1060-0011
 CDP                   : N/A
 
 1.bat
 @echo off
 DEL 1.txt
 findstr "^Project" 2.ini>1.txt
 
 2.bat
 @echo off
 setlocal
 for /f "delims=: tokens=2" %%i in (1.txt) do (
 set biosv=%%i
 )
 echo.%biosv% >bios.dat
 
 endlocal
 
 以上,想將1.bat與2.bat合并,該將1.bat如何加入到2.bat中呢?
 
Today I'm working on the FOR statement and don't know how to combine the for statement with findstr. The following are the separate programs. Please help. Thanks~
 Requirement: Extract the content after the project field
 
 2.ini
 Hierarchy ID          : Normal Board
 Chip SKU              : 250
 Project               : 1060-0011
 CDP                   : N/A
 
 1.bat
 @echo off
 DEL 1.txt
 findstr "^Project" 2.ini>1.txt
 
 2.bat
 @echo off
 setlocal
 for /f "delims=: tokens=2" %%i in (1.txt) do (
 set biosv=%%i
 )
 echo.%biosv% >bios.dat
 
 endlocal
 
 Above, I want to combine 1.bat and 2.bat. How should I add 1.bat into 2.bat?
 
 
 
 |  | 
|  2010-12-10 09:41 |  | 
|  | 
 
| qinchun36 高级用户
 
     据说是李先生
 
 
 积分 609
 发帖 400
 注册 2008-4-23
 状态 离线
 | 
| 『第 2 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
可以使用这种样式的语句来处理结果并且避免中间文件的产生: 
FOR /F  %x IN (' 有文字输出的命令行' ) DO ***
 
那个命令行用单引号包起来,顺便说一句,delims最好写在最后。
 for /f "tokens=2 delims=: " %%i in ('findstr "^Project" 2.ini') do
 
You can use statements in this style to process the result and avoid the generation of intermediate files: 
FOR /F  %x IN (' Command line with text output' ) DO ***
 
That command line is enclosed in single quotes, by the way, delims is best written at the end.
 for /f "tokens=2 delims=: " %%i in ('findstr "^Project" 2.ini') do
 
 
 
 |  | 
|  2010-12-10 10:19 |  | 
|  | 
 
| van416 初级用户
 
   
 
 
 
 积分 34
 发帖 30
 注册 2010-12-2
 状态 离线
 |  | 
|  2010-12-10 10:38 |  | 
|  | 
 
| yf6122010 新手上路
 
  
 
 
 
 积分 18
 发帖 18
 注册 2010-12-6
 状态 离线
 |  | 
|  2010-12-10 11:15 |  | 
|  | 
 
| a081910 新手上路
 
  
 
 
 
 积分 2
 发帖 2
 注册 2010-12-9
 来自 北京
 状态 离线
 |  | 
|  2010-12-10 15:11 |  | 
|  | 
 
| van416 初级用户
 
   
 
 
 
 积分 34
 发帖 30
 注册 2010-12-2
 状态 离线
 | 
| 『第 6 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
我有DOS下沒有findstr這個命令,用WINXP下的又不能用,用這個工具的能不能上偉一下給我 
I don't have the findstr command under DOS, and the one under WINXP can't be used. Can someone who has this tool kindly share it with me? 
 
 
 |  | 
|  2010-12-10 16:11 |  | 
|  | 
 
| Hanyeguxing 银牌会员
 
      正在学习中的菜鸟...
 
 
 积分 1039
 发帖 897
 注册 2009-3-1
 来自 在地狱中仰望天堂
 状态 离线
 | 
| 『第 7 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
这样不可以吗? @echo off&setlocal enabledelayedexpansionfor /f "tokens=1* delims=:" %%i in (1.ini) do (
 set i=%%i
 if /i "!i:~0,7!"=="Project" >>bios.dat echo %%j
 )
Is this not okay? @echo off&setlocal enabledelayedexpansionfor /f "tokens=1* delims=:" %%i in (1.ini) do (
 set i=%%i
 if /i "!i:~0,7!"=="Project" >>bios.dat echo %%j
 )
 
 
 
 |  
                  |  
  批处理之家 http://bbs.bathome.net/forum-5-1.html |  | 
|  2010-12-10 16:27 |  | 
|  | 
 
| van416 初级用户
 
   
 
 
 
 积分 34
 发帖 30
 注册 2010-12-2
 状态 离线
 | 
| 『第 8 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
for /f "tokens=1* delims=:" %%i in (1.ini) do (set i=%%i
 if /i "!i:~0,7!"=="Project" >>bios.dat echo %%j
 
 有幾句看不太明白
 
 tokens=1* 是什么意思?
 
 if /i "!i:~0,7!"=="Project" >>bios.dat echo %%j
 這一句也不明白,if /i   0,7是什么意思呢?
 
### Translation Result ###### 对于 `for /f "tokens=1* delims=:" %%i in (1.ini) do (` 部分:
 在 `for /f` 循环中,`tokens=1* delims=:` 的意思是:`tokens=1*` 表示将每行按 `delims=:` 定义的分隔符(这里是冒号)进行分割,取第一个标记赋给 `%%i`,剩下的部分赋给 `%%j`。
 
 ### 对于 `if /i "!i:~0,7!"=="Project" >>bios.dat echo %%j` 部分:
 - `if /i`:表示不区分大小写进行比较。
 - `!i:~0,7!`:这是字符串截取操作,`~0,7` 表示从字符串 `!i!` 的开头(索引0)开始,截取7个字符。
 - 整句意思是:如果 `!i!` 这个变量从开头开始的7个字符不区分大小写等于 "Project",就将 `%%j` 追加输出到 `bios.dat` 文件中。
 
 So the translation of the relevant text is:
 
 ### For the part `for /f "tokens=1* delims=:" %%i in (1.ini) do (`:
 In the `for /f` loop, `tokens=1* delims=:` means: `tokens=1*` means that each line is split by the delimiter defined by `delims=:` (here is the colon), the first token is assigned to `%%i`, and the remaining part is assigned to `%%j`.
 
 ### For the part `if /i "!i:~0,7!"=="Project" >>bios.dat echo %%j`:
 - `if /i` means: perform a case-insensitive comparison.
 - `!i:~0,7!`: this is a string intercept operation, `~0,7` means intercept 7 characters from the beginning (index 0) of the string `!i!`.
 - The whole sentence means: if the 7 characters from the beginning of the `!i!` variable are case-insensitively equal to "Project", then append and output `%%j` to the `bios.dat` file.
 
 
 
 |  | 
|  2010-12-10 17:02 |  | 
|  | 
 
| Hanyeguxing 银牌会员
 
      正在学习中的菜鸟...
 
 
 积分 1039
 发帖 897
 注册 2009-3-1
 来自 在地狱中仰望天堂
 状态 离线
 |  | 
|  2010-12-10 17:26 |  | 
|  | 
 
| van416 初级用户
 
   
 
 
 
 积分 34
 发帖 30
 注册 2010-12-2
 状态 离线
 | 
| 『第 10 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
嗯 ,好的,謝謝,可以用的
 現在不明白的是 if /i "!i:~0,7!"=="Project" 其中!i:~0,7是什么意思呢?
 
Um, okay, thanks, it can be used. Now what I don't understand is in "if /i "!i:~0,7!"=="Project" what does!i:~0,7 mean? 
 
 
 |  | 
|  2010-12-10 17:30 |  | 
|  | 
 
| Hanyeguxing 银牌会员
 
      正在学习中的菜鸟...
 
 
 积分 1039
 发帖 897
 注册 2009-3-1
 来自 在地狱中仰望天堂
 状态 离线
 |  | 
|  2010-12-10 17:38 |  | 
|  | 
 
| van416 初级用户
 
   
 
 
 
 积分 34
 发帖 30
 注册 2010-12-2
 状态 离线
 | 
| 『第 12 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
謝謝。。明白了
 還有一個問題:for命令在純MS-DOS下好像不支持for /f語句,請問這個for命令可以下載嗎?
 
Thanks..Got it
 Another question: The for command in pure MS-DOS doesn't seem to support the for /f statement. Can this for command be downloaded?
 
 
 
 |  | 
|  2010-12-10 18:12 |  | 
|  | 
 
| Hanyeguxing 银牌会员
 
      正在学习中的菜鸟...
 
 
 积分 1039
 发帖 897
 注册 2009-3-1
 来自 在地狱中仰望天堂
 状态 离线
 |  | 
|  2010-12-10 18:24 |  | 
|  | 
 
| van416 初级用户
 
   
 
 
 
 积分 34
 发帖 30
 注册 2010-12-2
 状态 离线
 | 
| 『第 14 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
怎么更新DOS下FOR命令呢? 我好像找不到呢? 
How to update the FOR command under DOS? I can't seem to find it? 
 
 
 |  | 
|  2010-12-10 18:31 |  | 
|  | 
 
| Hanyeguxing 银牌会员
 
      正在学习中的菜鸟...
 
 
 积分 1039
 发帖 897
 注册 2009-3-1
 来自 在地狱中仰望天堂
 状态 离线
 | 
| 『第 15 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
@echo offfind /i "Project" 2.ini>han_1.txt
 more +2 han_1.txt>han_2.txt
 set/p k=<han_2.txt
 set k=%k:*:=%
 del /q han_*
 echo %k:~1% >bios.dat
 
 Last edited by Hanyeguxing on 2010-12-10 at 19:37 ] 
```@echo off
 find /i "Project" 2.ini>han_1.txt
 more +2 han_1.txt>han_2.txt
 set/p k=<han_2.txt
 set k=%k:*:=%
 del /q han_*
 echo %k:~1% >bios.dat
 ```
 
 Last edited by Hanyeguxing on 2010-16-10 at 19:37 ]
 
 
 
 
 |  
                  |  
  批处理之家 http://bbs.bathome.net/forum-5-1.html |  | 
|  2010-12-10 19:32 |  |