- @echo off
- :: 把下一行的数字复制到前面一行的后面,并用空格分开
- setlocal enabledelayedexpansion
- for /f %%i in (test.txt) do (
- set /a count+=1
- set first=!second!
- set second=%%i
- if !count! gtr 1 echo !first! !second!
- )
- pause
- 在这里命令for在解析文件时,省略了对变量的描述。默认的是"tokens=*"。
- set /a expression :/a 命令开关指定set命令计算expression表达式。
- if命令里使用了比较运算符gtr(greater than)
经典批处理
分析
两行字符串,那所得的结果是:经典批处理 分析
cheers! that is funny.
如果我不满意,我想想偶数行的加到奇数行上去,那
- @echo off
- ::append even line to odd line
- setlocal enabledelayedexpansion
- for /f %%i in (test.txt) do (
- set /a count+=1
- set first=!second!
- set second=%%i
- set /a mod=!count!%%2
- if !mod! equ 0 echo !first! !second!
- )
- pause
经常进行拓展训练,能让你体会的更多,不是么?