读取文件test1.txt 中的第1,3,4,6,7行到test2.txt
test1 内容
port a 1
port b 2
port c 3
port d 4
port e 5
port f 6
port g 7
port h 8
port i 9
test1 内容
port a 1
port b 2
port c 3
port d 4
port e 5
port f 6
port g 7
port h 8
port i 9
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off
for /f "delims=" %%i in ('findstr "1 3 4 6 7" a.txt') do (set num=%%i
>>test2.txt call,echo %%num%%
)
pause
@echo off
setlocal enabledelayedexpansion
set row=0
type nul>"C:\test\test2.txt"
for /f "tokens=1,2* delims=:" %%a in ('findstr /n .* "C:\test\test1.txt"') do (
set /a row+=1
if !row! equ 1 (>>"C:\test\test2.txt" echo %%b)
if !row! equ 3 (>>"C:\test\test2.txt" echo %%b)
if !row! equ 4 (>>"C:\test\test2.txt" echo %%b)
if !row! equ 6 (>>"C:\test\test2.txt" echo %%b)
if !row! equ 7 (>>"C:\test\test2.txt" echo %%b)
)
Originally posted by HAT at 2008-5-27 11:15:
@echo off
setlocal enabledelayedexpansion
set row=0
type nul>"C:\test\test2.txt"
for /f "tokens=1,2* delims=:" %%a in ('findstr /n .* "C:\test\test1.txt"' ...
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (test1.txt) do (
set str=%%i
if defined str (
set /a n+=1
set _!n!=!str!
)
)
for %%i in (1 3 4 6 7) do echo !_%%i!>>test2.txt
pause>nul
| 评分人 | 分数 | 时间 |
|---|---|---|
| WANKOILZ | +1 | 2008-05-31 11:24 |
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('findstr/n ".*" test1.txt') do (
set str=%%i&set str=!str:*:=!
set/a n+=1
set _!n!=!str!
)
for %%i in (1 3 4 6 7) do echo.!_%%i!>>test2.txt
pause
@echo off
for %%a in (1 3 4 6 7) do set .%%a=a
for /f "tokens=1* delims=:" %%a in ('findstr/n ".*" test1.txt') do (
if defined .%%a echo.%%b
)
pause
Originally posted by 26933062 at 2008-5-31 14:29:
@echo off&setlocal enabledelayedexpansion
for %%a in (1 3 4 6 7) do set .%%a=a
for /f "tokens=1* delims=:" %%i in ('findstr/n ".*" test1.txt') do (
if defined . ...
Originally posted by terse at 2008-5-31 17:00:
楼兄笔误哦 %%i应该%%a
延迟也可以去了吧
Originally posted by 26933062 at 2008-5-31 14:29:
@echo off
for %%a in (1 3 4 6 7) do set .%%a=a
for /f "tokens=1* delims=:" %%a in ('findstr/n ".*" test1.txt') do (
if defined .%%a echo.%%b
)
pause
echo. 这个。就可以解决了,兄弟我又学了一招。 十分感谢大家帮助