Board logo

标题: [文本处理] [已解决]批处理如何在win7 x64下更改指定行的内容? [打印本页]

作者: zhanghdong    时间: 2011-4-4 14:26     标题: [已解决]批处理如何在win7 x64下更改指定行的内容?

本帖最后由 zhanghdong 于 2011-4-4 19:05 编辑

本来想用sed实现此功能,但是发现sed在win7 x64下无法运行,白发贴提问了,谢谢zm900612在上一贴的回答了。
特此再提问一下,如何在win7 x64位系统下用自带的命令或者类似sed功能的其它软件实现此批处理。
  1. <?xml version="1.0" encoding="UTF-16"?>
  2. <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  3.   <RegistrationInfo>
  4.     <Source>$(@%systemroot%\system32\defragsvc.dll,-800)</Source>
  5.     <Author>$(@%systemroot%\system32\defragsvc.dll,-801)</Author>
  6.     <Description>$(@%systemroot%\system32\defragsvc.dll,-802)</Description>
  7.     <URI>Microsoft\Windows\Defrag\ScheduledDefrag</URI>
  8.   </RegistrationInfo>
  9.   <Triggers>
  10.     <CalendarTrigger id="DefragWeeklyTrigger">
  11.       <StartBoundary>2011-04-04T01:00:00</StartBoundary>
  12.       <Enabled>true</Enabled>
  13.       <ScheduleByWeek>
  14.       <AllowStartOnDemand>true</AllowStartOnDemand>
  15.       <Enabled>true</Enabled>
  16.       <Hidden>false</Hidden>
复制代码
  1. 在不改动15行的情况下把12行的代码
  2. <Enabled>true</Enabled>
  3. 改为
  4. <Enabled>false</Enabled>
复制代码
  1. 在不改动12行的情况下把15行的代码
  2. <Enabled>true</Enabled>
  3. 改为
  4. <Enabled>false</Enabled>
复制代码

作者: CrLf    时间: 2011-4-4 14:47

本帖最后由 zm900612 于 2011-4-4 14:49 编辑
  1. @echo off
  2. for /f "tokens=1* delims=:^" %%a in ('findstr /n .* test') do (
  3. if %%a==12 (
  4. for /f "tokens=1-3* delims=^<^>" %%c in ("%%b") do echo %%c^<%%d^>false^<%%f
  5. ) else echo %%b
  6. )
  7. pause
复制代码

作者: zhanghdong    时间: 2011-4-4 15:00

@echo off
for /f "tokens=1* delims=:^" %%a in ('findstr /n .* test') do (
if %%a==12 (
for /f "tokens=1-3* delims=^" %%c in ("%%b") do echo %%c^false^
zm900612 发表于 2011-4-4 14:47


大侠好厉害。。代码测试有效,如何输出更改文件呢??
作者: CrLf    时间: 2011-4-4 16:48

  1. @echo off
  2. (for /f "tokens=1* delims=:^" %%a in ('findstr /n .* test') do (
  3. if %%a==12 (
  4. for /f "tokens=1-3* delims=^<^>" %%c in ("%%b") do echo %%c^<%%d^>false^<%%f
  5. ) else echo %%b
  6. ))>tmp
  7. move tmp test
  8. pause
复制代码

作者: Batcher    时间: 2011-4-4 18:10

3# zhanghdong


以后提问的时候最好能把自己的系统环境、问题背景等都说清楚
作者: zhanghdong    时间: 2011-4-4 19:06

@echo off
(for /f "tokens=1* delims=:^" %%a in ('findstr /n .* test') do (
if %%a==12 (
for /f "tokens=1-3* delims=^" %%c in ("%%b") do echo %%c^false^tmp
move tmp test
pause
zm900612 发表于 2011-4-4 16:48


十分感谢。学习了。。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2