我在D:\CNC里放有许多.B3文件,需要批处理删除(PART RIPCUT)和(BLOCK)之间的行。但有的文件没有(PART RIPCUT),这些文件不做修改。请各位朋友帮忙!文件内容如下:
(17)
%
P17
(STD WADR)
(ORIGIN=BOTTOM LEFT)
(METRIC)
G71
(RELATIVE)
G91
(PART 1/Top Cheek)
G00X616.8Y820.0
G41
M04
F8000.0
G01X0.0Y-4.0
G03X144.0Y-144.0I144.0J-0.0
G01X50.0Y0.0
G01X4.0Y0.0
M03
G40
(PART 2/Left Throat Wrapper)
G00X-221.2Y205.0
G41
M04
G01X-4.0Y0.0
G01X0.0Y-350.0
G01X0.0Y-4.0
M03
G40
G00X400.0Y4.0
G41
M04
G01X-4.0Y0.0
G01X-99.2Y0.0
G01X-0.8Y3.0
G01X0.0Y-4.0
M03
G40
(PART 1/Bottom Cheek)
G00X429.1Y-813.0
(PART 2/Left Throat Wrapper)
G00X-25.1Y821.0
G41
M04
G01X-4.0Y0.0
G01X-99.2Y0.0
G01X0.0Y-350.0
G01X0.0Y-4.0
M03
G40
G00X361.2Y200.6
G41
M04
G01X0.0Y-4.0
G01X0.0Y-99.2
G01X0.0Y99.2
G01X350.0Y0.0
G01X4.0Y0.0
M03
G40
G00X25.0Y-418.0
G41
M04
G01X0.0Y-4.0
G01X0.0Y-99.2
G01X350.0Y0.0
G01X4.0Y0.0
M03
G40
G00X-4.0Y-392.0
G41
M04
G01X0.0Y-4.0
G01X0.0Y-99.2
G01X350.0Y0.0
G01X4.0Y0.0
M03
G40
(PART 1/Left Throat Wrapper)
G00X345.8Y-385.6
G41
M04
G01X-4.0Y0.0
G01X-49.2Y0.0
G01X0.0Y-4.0
M03
G40
(PART 1/Right Throat Wrapper)
G00X4.0Y365.0
G41
M04
G01X-4.0Y0.0
G01X-49.2Y0.0
G01X0.0Y-350.0
G01X0.0Y-4.0
M03
G40
(PART 2/Left Throat Wrapper)
G00X-13.8Y824.6
G41
M04
G01X0.0Y-4.0
G01X0.0Y-99.2
G01X-3.0Y-0.8
G01X350.0Y0.0
G01X4.0Y0.0
M03
G40
(PART RIPCUT)
G00X23.8Y-1187.6
M04
G01X0.0Y1500.0
M03
(BLOCK)
G00X-1937.6Y-1500.0
(END OF SHEET)
(END OF PROGRAM)
M30
我现有一段代码,但处理文件时,如果部分文件没有(PART RIPCUT),那么(BLOCK)及下面的内容会出现两次重复,怎么解决?- @echo off&setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /s/b D:\CNC\*.B3') do (
- cd.>"%%a_"
- for /f "tokens=1,2 delims=:" %%i in ('findstr /n "." "%%a"') do (
- set "var=%%j"
- if not defined n echo %%j
- if defined m echo %%j
- if "!var:~1,7!"=="PART RI" set n=%%i
- if "!var:~1,5!"=="BLOCK" set m=%%i & echo %%j
- ) >> "%%a_"
- set n=
- set m=
- move "%%a_" "%%a"
- )
- exit
复制代码
|