- ·上一篇文章:DEBUG模拟蓝屏
- ·下一篇文章:SED单行脚本快速参考
- ·百度中搜索更多的关于“读取文件中的某几行到另外一个文件”相关内容
- ·谷歌中搜索更多的关于“读取文件中的某几行到另外一个文件”相关内容
- ******申明******
- 本站文章内容有部分为收录网络中其他网友内容,DOS资源站不保证所有的代码都适合你使用。
- 由于编辑匆忙,有可能造成某些脚本文件出现丢失代码或代码无法运行的情况,请网友根据情况自行修改。
- 如果能将出错部分反馈给我,那就更好了。
读取文件中的某几行到另外一个文件
读取文件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
@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
如果test1中的文件内容是这样
SET Port1=0
SET Port2=1
SET Port2=low
SET Port1=0
SET Port2=0
SET Port1=0
SET Port2=0
SET Port1=0
SET Port2=0
SET Port3=0
SET Port4=0
SET Port5=1
SET Port5=full
SET Port6=1
SET Port6=full
SET Port1=0
SET Port2=0
SET Port1=0
SET Port2=0
SET Port1=1
SET Port1=full
SET Port2=0
SET Port1=1
SET Port1=full
SET Port2=0
SET Port3=0
SET Port4=0
SET Port5=0
SET Port6=0
@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

