[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 【已解决】批处理删除 某一段代码

本帖最后由 lovekix 于 2023-7-19 19:13 编辑

比如我有一段代码
]通过批处理  能删除吗?  每次都手动查找 然后删除太麻烦
  1. <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">
  2. <uap:VisualElements DisplayName="ms-resource:WindowsBackup/Resources/WindowsBackupHostName" Description="ms-resource:WindowsBackup/Resources/WindowsBackupDescription" Square150x150Logo="WindowsBackup\Assets\MedTile.png" Square44x44Logo="WindowsBackup\Assets\AppList.png" BackgroundColor="transparent">
  3. ...
  4. </uap:VisualElements>
  5. <Extensions>
  6. <uap:Extension Category="windows.protocol">
  7. <uap:Protocol Name="ms-windowsbackup" ReturnResults="optional"/>
  8. </uap:Extension>
  9. <uap3:Extension Category="windows.appExtension">
  10. <uap3:AppExtension Name="com.microsoft.windows.extensionpackage" Id="WindowsBackup" DisplayName="Extension Metadata">
  11. <uap3:Properties>
  12. <PackageAliases>
  13. <PackageAlias>WindowsBackupAlias</PackageAlias>
  14. </PackageAliases>
  15. </uap3:Properties>
  16. </uap3:AppExtension>
  17. </uap3:Extension>
  18. <uap3:Extension Category="windows.appExtension">
  19. <uap3:AppExtension Name="com.microsoft.windows.app.windowsbackup" Id="WindowsBackup" DisplayName="Extension Metadata"/>
  20. </uap3:Extension>
  21. <uap3:Extension Category="windows.appExtension">
  22. <uap3:AppExtension Name="com.microsoft.windows.extensions.xaml" Id="WindowsBackup" DisplayName="Microsoft Windows Extensions">
  23. <uap3:Properties>
  24. <Classes>
  25. <WindowsBackupControl>WindowsBackup.WindowsBackupControl</WindowsBackupControl>
  26. </Classes>
  27. <MetadataProviders>
  28. <Provider>WindowsBackup.XamlMetaDataProvider</Provider>
  29. </MetadataProviders>
  30. <ResourceDictionaries>
  31. <ResourceDictionary>WindowsBackup.WindowsBackupResources</ResourceDictionary>
  32. </ResourceDictionaries>
  33. </uap3:Properties>
  34. </uap3:AppExtension>
  35. </uap3:Extension>
  36. </Extensions>
  37. <uap:ApplicationContentUriRules>
  38. <uap:Rule Type="include" Match="https://login.live.com/"/>
  39. <uap:Rule Type="include" Match="https://signup.live.com/"/>
  40. <uap:Rule Type="include" Match="https://account.live.com/"/>
  41. </uap:ApplicationContentUriRules>
  42. </Application>
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

  1. <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">
复制代码
到</Application> 结束
中间有什么不重要

TOP

回复 2# lovekix
  1. sed "/<Application Id=\x22WindowsBackup\x22 Executable=\x22WindowsBackupClient.exe\x22 EntryPoint=\x22WindowsBackup.App\x22 uap10:TrustLevel=\x22mediumIL\x22 uap10:RuntimeBehavior=\x22windowsApp\x22>/,/<\/Application>/d" 1.txt > 2.txt
复制代码
命令行工具 sed.exe 下载地址:
http://bcn.bathome.net/s/tool/index.html?key=sed
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 77七 于 2023-7-19 12:19 编辑
  1. @echo off
  2. rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
  3. set "str1=<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
  4. set "str2=</Application>"
  5. setlocal enabledelayedexpansion
  6. set "str1=!str1:"="""!"
  7. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"!str1!" /c:"!str2!" "1.txt"') do if defined start (set end=%%a) else (set start=%%a)
  8. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "1.txt"') do (
  9. if %%a lss !start! echo=%%b
  10. if %%a gtr !end! echo=%%b
  11. ))>"2.txt"
  12. endlocal
  13. pause
复制代码
bat小白,请多指教!谢谢!

TOP

回复 3# Batcher


    不会用啊  

文件名是 appxmanifest.xml

TOP

回复 4# 77七


    不行啊   只是把  里面的内容全部复制出来了
  没有 删除  那一段代码

TOP

回复 6# lovekix


我测试是正常的。

将代码中两处 1.txt 改为你的文件名,再试试。
  如果不行 ,你把原文件传到网盘,发上来看看。
bat小白,请多指教!谢谢!

TOP

TOP

回复 8# lovekix


   你的实际文本与1楼提供的文本不符,1楼的文本行前缺少两个制表符,另外文本中存在多个 </Application>。先修改如下,有问题再说。
  1. @echo off
  2. rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
  3. set "str1= <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
  4. set "str2= </Application>"
  5. setlocal enabledelayedexpansion
  6. set "str1=!str1:"="""!"
  7. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"!str1!" "appxmanifest.xml"') do set start=%%a
  8. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"!str2!" "appxmanifest.xml"') do (
  9. if %%a gtr !start! (
  10. set end=%%a
  11. goto :next
  12. )
  13. )
  14. :next
  15. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
  16. if %%a lss !start! echo=%%b
  17. if %%a gtr !end! echo=%%b
  18. ))>"appxmanifest-2.xml"
  19. endlocal
  20. pause
复制代码
bat小白,请多指教!谢谢!

TOP

回复 9# 77七


   

!丢了

TOP

回复 10# lovekix


  
  1. @echo off
  2. rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
  3. set "str1= <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
  4. set "str2= </Application>"
  5. rem setlocal enabledelayedexpansion
  6. set "str1=%str1:"="""%"
  7. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str1%" "appxmanifest.xml"') do set start=%%a
  8. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str2%" "appxmanifest.xml"') do (
  9. if %%a gtr %start% (
  10. set end=%%a
  11. goto :next
  12. )
  13. )
  14. :next
  15. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
  16. set "str=%%b"
  17. setlocal enabledelayedexpansion
  18. if %%a lss %start% echo=!str!
  19. if %%a gtr %end% echo=!str!
  20. endlocal
  21. ))>"appxmanifest-2.xml"
  22. endlocal
  23. pause
复制代码
1

评分人数

bat小白,请多指教!谢谢!

TOP

回复 11# 77七

谢谢
    刀工完美
  1. @echo off
  2. rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
  3. set "str1= <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
  4. set "str2= </Application>"
  5. rem setlocal enabledelayedexpansion
  6. set "str1=%str1:"="""%"
  7. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str1%" "appxmanifest.xml"') do set start=%%a
  8. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str2%" "appxmanifest.xml"') do (
  9. if %%a gtr %start% (
  10. set end=%%a
  11. goto :next
  12. )
  13. )
  14. :next
  15. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
  16. set "str=%%b"
  17. setlocal enabledelayedexpansion
  18. if %%a lss %start% echo=!str!
  19. if %%a gtr %end% echo=!str!
  20. endlocal
  21. ))>"appxmanifest-2.xml"
  22. endlocal
  23. pause
复制代码

TOP

本帖最后由 lovekix 于 2023-7-28 10:24 编辑

回复 11# 77七






https://im.ge/i/9D1sha

无法打开    (15行的)
(for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do
加了两行命令   解决了
  1. @echo off
  2. xcopy "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml" "%cd%\" /k /c /q /r /y
  3. rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
  4. set "str1= <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
  5. set "str2= </Application>"
  6. rem setlocal enabledelayedexpansion
  7. set "str1=%str1:"="""%"
  8. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str1%" "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml"') do set start=%%a
  9. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str2%" "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml"') do (
  10. if %%a gtr %start% (
  11. set end=%%a
  12. goto :next
  13. )
  14. )
  15. :next
  16. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
  17. set "str=%%b"
  18. setlocal enabledelayedexpansion
  19. if %%a lss %start% echo=!str!
  20. if %%a gtr %end% echo=!str!
  21. endlocal
  22. ))>"C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml"
  23. endlocal
  24. del "appxmanifest.xml"
  25. pause
复制代码

TOP

请教:我也是需要删除某一段代码,有点不同的是只是删除str1至str2之间代码包括str1,而str2不删除,多个文件需要处理

TOP

T1
G00 Y48.62 F7500
G01 X9.8 F5000
G00 Y52.17 F7500
G01 X-15 F5000
G00 Y201.0 F7500
G01 X23.2 F3000
G01 X-15 F3000
G00 Y239.62 F7500
G01 X9.8 F5000
G00 Y243.17 F7500
G01 X-15 F5000
T2
G00 X-15 Y241.4 F7500
G01 X25 F5000
G01 X-15 F5000
G00 Y50.4 F7500
G01 X25.0 F5000
G01 X-15 F5000
M05
M30

TOP

返回列表