[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
太赞了,我试了好几次循环都没成功,底子还是太弱了,再次感谢

TOP

回复 21# Zhanggli
已修改

TOP

回复 16# Zhanggli


  
  1. @echo off
  2. for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
  3. call :1 "%%i"
  4. )
  5. pause & exit
  6. :1
  7. setlocal
  8. for /f "tokens=1* delims=:" %%a in ('findstr /nxr /c:"M05" /c:"T2" "%~1"') do (
  9. if not defined s (
  10. set s=%%a
  11. ) else (
  12. set e=%%a
  13. )
  14. )
  15. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "%~1"') do (
  16. if %%a lss %s% (
  17. echo=%%b
  18. ) else if %%a equ %e% (
  19. echo=%%b
  20. echo=M55
  21. ) else if %%a gtr %e% (
  22. echo=%%b
  23. )
  24. ))>$
  25. move /y $ "%~1"
  26. endlocal
  27. exit /b
复制代码
bat小白,请多指教!谢谢!

TOP

不过如果是多个文件同样处理的话需要引入临时文件变量temp吧?

TOP

我之前的思路也是和前面的定义了两个字符串变量来处理反倒没搞好

TOP

感谢qixiaobin,真的很简洁明了,再次感谢

TOP

本帖最后由 qixiaobin0715 于 2023-9-1 17:21 编辑
  1. @echo off
  2. for /f "delims=" %%x in ('dir /b /a-d *.txt') do (
  3.     set n=0
  4.     (for /f "delims=" %%i in ('type "%%x"') do (
  5.         if "%%i"=="T2" set n=
  6.         if defined n echo,%%i
  7.         if "%%i"=="M05" (
  8.             set n=0
  9.             echo,%%i
  10.             echo,M55
  11.         )
  12.     ))>"New-%%x"
  13. )
  14. pause
复制代码

TOP

回复 15# Zhanggli
可用第3方工具sed( http://bcn.bathome.net/tool/4.9/sed.exe
  1. sed -e"/T2/,/M05/{/M05/!d;s/M05/M05\nM55/;}" 1.txt>2.txt
复制代码

TOP

现在需要删除的是T2-M05之间的代码,包括T2行,但是不包括M05,不同文件这两者之间的代码会有不同行数,另外在M05后面加一个指令M55,多个文件需要同样处理,我总是循环不起来。

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

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

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

回复 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

回复 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

回复 9# 77七


   

!丢了

TOP

返回列表