返回列表 发帖

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

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

比如我有一段代码
]通过批处理  能删除吗?  每次都手动查找 然后删除太麻烦
<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">
<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">
...
</uap:VisualElements>
<Extensions>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="ms-windowsbackup" ReturnResults="optional"/>
</uap:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.windows.extensionpackage" Id="WindowsBackup" DisplayName="Extension Metadata">
<uap3:Properties>
<PackageAliases>
<PackageAlias>WindowsBackupAlias</PackageAlias>
</PackageAliases>
</uap3:Properties>
</uap3:AppExtension>
</uap3:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.windows.app.windowsbackup" Id="WindowsBackup" DisplayName="Extension Metadata"/>
</uap3:Extension>
<uap3:Extension Category="windows.appExtension">
<uap3:AppExtension Name="com.microsoft.windows.extensions.xaml" Id="WindowsBackup" DisplayName="Microsoft Windows Extensions">
<uap3:Properties>
<Classes>
<WindowsBackupControl>WindowsBackup.WindowsBackupControl</WindowsBackupControl>
</Classes>
<MetadataProviders>
<Provider>WindowsBackup.XamlMetaDataProvider</Provider>
</MetadataProviders>
<ResourceDictionaries>
<ResourceDictionary>WindowsBackup.WindowsBackupResources</ResourceDictionary>
</ResourceDictionaries>
</uap3:Properties>
</uap3:AppExtension>
</uap3:Extension>
</Extensions>
<uap:ApplicationContentUriRules>
<uap:Rule Type="include" Match="https://login.live.com/"/>
<uap:Rule Type="include" Match="https://signup.live.com/"/>
<uap:Rule Type="include" Match="https://account.live.com/"/>
</uap:ApplicationContentUriRules>
</Application>COPY
1

评分人数

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

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

TOP

回复 2# lovekix
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.txtCOPY
命令行工具 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 编辑
@echo off
rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
set "str1=<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
set "str2=</Application>"
setlocal enabledelayedexpansion
set "str1=!str1:"="""!"
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)
(for /f "tokens=1* delims=:" %%a in ('findstr /n .* "1.txt"') do (
if %%a lss !start! echo=%%b
if %%a gtr !end! echo=%%b
))>"2.txt"
endlocal
pauseCOPY
bat小白,请多指教!谢谢!

TOP

回复 3# Batcher


    不会用啊  

文件名是 appxmanifest.xml

TOP

回复 4# 77七


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

TOP

回复 6# lovekix


我测试是正常的。

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

TOP

TOP

回复 8# lovekix


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

TOP

回复 9# 77七


   

!丢了

TOP

回复 10# lovekix


  
@echo off
rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
set "str1= <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
set "str2= </Application>"
rem setlocal enabledelayedexpansion
set "str1=%str1:"="""%"
for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str1%" "appxmanifest.xml"') do set start=%%a
for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str2%" "appxmanifest.xml"') do (
if %%a gtr %start% (
set end=%%a
goto :next
)
)
:next
(for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
set "str=%%b"
setlocal enabledelayedexpansion
if %%a lss %start% echo=!str!
if %%a gtr %end% echo=!str!
endlocal
))>"appxmanifest-2.xml"
endlocal
pauseCOPY
1

评分人数

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

TOP

回复 11# 77七

谢谢
    刀工完美
@echo off
rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
set "str1= <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
set "str2= </Application>"
rem setlocal enabledelayedexpansion
set "str1=%str1:"="""%"
for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str1%" "appxmanifest.xml"') do set start=%%a
for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str2%" "appxmanifest.xml"') do (
if %%a gtr %start% (
set end=%%a
goto :next
)
)
:next
(for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
set "str=%%b"
setlocal enabledelayedexpansion
if %%a lss %start% echo=!str!
if %%a gtr %end% echo=!str!
endlocal
))>"appxmanifest-2.xml"
endlocal
pauseCOPY

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
加了两行命令   解决了
@echo off
xcopy "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml" "%cd%\" /k /c /q /r /y
rem http://bbs.bathome.net/redirect.php?goto=findpost&ptid=12042&pid=76476
set "str1= <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"
set "str2= </Application>"
rem setlocal enabledelayedexpansion
set "str1=%str1:"="""%"
for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str1%" "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml"') do set start=%%a
for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"%str2%" "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml"') do (
if %%a gtr %start% (
set end=%%a
goto :next
)
)
:next
(for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
set "str=%%b"
setlocal enabledelayedexpansion
if %%a lss %start% echo=!str!
if %%a gtr %end% echo=!str!
endlocal
))>"C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\appxmanifest.xml"
endlocal
del "appxmanifest.xml"
pauseCOPY

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

返回列表