求两个bat批处理命令大全 提取文本某些行内容一个不删除提取内容 一个删除提取内容

批处理如何从一个文档里提取某段字符串并写到另一个文档里_百度知道
批处理如何从一个文档里提取某段字符串并写到另一个文档里
&#92.LOG&D,但里面有许多乱码)PACK,如;D.TXT 中有许多文件路径;A15;LOG&#92:提取的字符 A15;D;LOG\1:&#92文件C:\2.TXT&C18:02155A;&quot.TXT:&#92: 后面的6个字符;中是PACK;A15;按照指定的路径搜索该文件(绝对有这个文件:&#92:&quot.LOG&quot,则输出文件名称(不包括后缀). 输出到C;LOG&#92,并提取里面的某段信息(绝对只有一个,因为已经过滤过了):&quot,格式如下如
d截取内容为02512D 也有可能;&#47?h:X A15?A15;
PACK,如;蘟D,则输出文件名称(不包括后缀)8;LOG&#92?&lt?寴&#39:&#92,文件没有这个信息:这个字符; 无PACK:&quot.LOG&quot:02512D
Jt8;
提问者采纳
if defined s (
setlocal enabledelayedexpansion
set &con))&gt:X )else echo %%i 文件没找到&gt!&c;i &quot!
set &usebackq tokens=*&s=%%j&s=;^|find /delims=& %%i in (&&#39.txt&
set &quot!s;s=&%%i&c;
echo %%~f &quot!&)do set &quot,6;%%i&2:\type &quot:=注意一下 关键字符串&PACK;)do (
if exist &quot.txt&quot:~:*PACK;s=;con echo %%i
for &#47!s:&quot:\ %%j in ('PACK;中全半角必须与实际一致(代码中共有两处)@echo off(for &#47:&f &
)else echo %%~ni
提问者评价
按照你说的,真的成功了,好开心,谢谢你!
其他类似问题
为您推荐:
批处理的相关知识
其他1条回答
是固定PACK描述不清晰,根据一个文档里的路径来提取:后面的所有字符。PACK后面的一第一个开始的到第6个字符。你是要,还是只截取,路径文件里的某些字符。
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁多个文本文档 txt类型文件 批量处理 批量删除 批量修改 批量替换 批量查找 批量添加
[问题点数:40分]
多个文本文档 txt类型文件 批量处理 批量删除 批量修改 批量替换 批量查找 批量添加
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2016年1月 总版技术专家分月排行榜第二2015年11月 总版技术专家分月排行榜第二2015年10月 总版技术专家分月排行榜第二
优秀小版主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。批处理提取不同行上的内容的代码
字体:[ ] 类型:转载 时间:
这个网页显示如何阅读的具体行从一个文本文件。有许多方法可以有供/ F命令读取输入文件
for instance:- for /f "delims=" %%a in (input.txt) do ... for /f "delims=" %%a in ('type input.txt') do ... for /f "delims=" %%a in ('more ^& input.txt') do ... However, only the last method (using the more command) will give consistent results across Windows NT, 2000, XP and 2003. The first method does not recognise unicode files. Also, the usebackq switch must be used if the input filename contains spaces. The second method, using the type command, also fails to recognise unicode files on Windows 2000, XP and 2003 if the input file does not begin with a bit order mark (BOM). In all the examples, assume the contents of of the file numbers.txt to be:- one two three four five six seven eight nine ten Displaying the first line This example prints one. @echo off & setlocal ENABLEEXTENSIONS set "first=" for /f "delims=" %%a in ('more ^& numbers.txt') do ( if not defined first set first=%%a ) echo/%first% Displaying the first X lines This example prints one, two and three. @echo off & setlocal ENABLEEXTENSIONS set "lines=3" set i=-1 set "ok=" for /f "delims=" %%a in ('more ^& numbers.txt') do ( set/a i+=1 & for /f %%z in ('echo/%%i%%') do ( if "%%z"=="%lines%" set ok=1 ) if not defined ok echo/%%a ) Displaying the last line This example prints ten. @echo off & setlocal ENABLEEXTENSIONS for /f "delims=" %%a in ('more ^& numbers.txt') do set "last=%%a" echo/%last% Displaying the last X lines This example prints nine and ten. @echo off & setlocal ENABLEEXTENSIONS set "lines=2" for /f %%a in ('find/c /v "" ^& numbers.txt') do set/a skip=%%a-lines for /f "delims=" %%a in ('more/e +%skip% ^& numbers.txt') do ( echo/%%a ) Displaying the Nth line This example prints three. Note that instead of using the more command's /e switch, the skip option could have been used with the for /f command, however, this fails is it is set to any number less than one. @echo off & setlocal ENABLEEXTENSIONS set LineNo=3 set "line=" set/a LineNo-=1 for /f "delims=" %%a in ('more/e +%LineNo% ^& numbers.txt') do ( if not defined line set "line=%%a" ) echo/%line% Displaying the Nth line plus X number of lines This example prints five and six. @echo off & setlocal ENABLEEXTENSIONS set start=5 set "lines=2" set/a i=-1,start-=1 set "ok=" for /f "delims=" %%a in ('more/e +%start% ^& numbers.txt') do ( set/a i+=1 & for /f %%z in ('echo/%%i%%') do ( if "%%z"=="%lines%" set ok=1 ) if not defined ok echo/%%a )
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具批处理从多个文件提取某字符串到另一个文件中_百度知道
批处理从多个文件提取某字符串到另一个文件中
我的e盘有多个以E:\*_RunWork_s*\GameServer\conf\world.conf这种类型命名的文件world.co订抚斥幌俪呵筹童船阔nf文件内容如下:&WorldDatabase Hostname = &127.0.0.1& Username = &root& Password = &dga2ebv5zdfz& Name = &gamedb_s1& Port = &12345&&&Listen Host = &0.0.0.0& WorldServerPort = &10005&&&LogLevel File=&0& World=&0& M_useIrc=&0&&&Log Cheaters=&0& GMCommands=&0& Player=&0& TimeStamp=&0&&&RemoteConsole Enabled=&1& Host=&0.0.0.0& Port=&9994& AllowIP=&127.0.0.1,127.0.0.1&&希望通过批处理实现提取s1
这三个数据到e:\port.txt文件中。格式如下:s1
提问者采纳
@Echo&Off&Setlocal&EnabledelayedexpansionFor&/f&&tokens=*&&%%i&in&('dir&/a-d&/b&/s&&%~dp0world.conf&')&do&(&&&&For&/f&&tokens=2&delims=_&&%%a&in&('Type&&%%i&^|findstr&/i&/c:&WorldDatabase&Hostname&')&do&(Set&a=%%a&Set&a=!a:~0,2!)&&&&For&/f&&tokens=3&delims==&&%%b&in&('Type&&%%i&^|findstr&/i&/c:&Listen&Host&')&do&(Set&b=%%b&Set&b=!b:~2,5!)&&&&For&/f&n订抚斥幌俪呵筹童船阔&tokens=4&delims==&&%%c&in&('Type&&%%i&^|findstr&/i&/c:&RemoteConsole&Enabled&')&do&(Set&c=%%c&Set&c=!c:~1,4!)&&&&Echo&!a!&!b!&!c!&&&e:\port.txt&)Start&&&&&e:\port.txt&Pause因为要提取的数据每行格式都不同,所以写了三行分别提取.把批处理和要处理的world.conf放在一起使用.
提问者评价
来自团队:
其他类似问题
为您推荐:
批处理的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁如何快速提取TXT文档中词语出现次数?比如一篇TXT文档中有许多词语多次出现,能否设置这样一个批处理或者程序来统计文档中各个词语出现的次数?
很简单,你把TXT里的全部复制到WORD里,然后按搜索,输入想查找的字或字符,查找,就出现了.具体的:打开TXT——按“ctrl+a”——“ctrl+c”新建一个word——按“ctrl+v”——"ctrl+f"——输入所查字符——搜索
为您推荐:
其他类似问题
用编辑里的查找就可以了
扫描下载二维码

我要回帖

更多关于 bat批处理命令大全 的文章

 

随机推荐