标题: [文本处理] [已解决]求助BAT脚本文本处理达到替换目的 [打印本页]
作者: gaoyh2008 时间: 2019-11-13 17:26 标题: [已解决]求助BAT脚本文本处理达到替换目的
本人是新手,求大侠帮忙看看如何用批处理达到替换目的,成分感谢!
作者: gaoyh2008 时间: 2019-11-13 17:41
在线等,哪位大侠帮忙看看
作者: gaoyh2008 时间: 2019-11-13 18:10
本帖最后由 gaoyh2008 于 2019-11-13 18:16 编辑
%
P1394
N1 G92
N2 G90
N3 G00 Z0
N4 G09
N5 G201
N6 G202
N7 G203
N8 G54
N9 M7
N10 G00 X-15.000 Z41.680
N11 X-26.078 Y-47.322
N12 X3.797 Y-20.723
N13 G01 X5.172 Y-19.499 Z41.680 F3000
N14 X6.601 Y-18.096 Z41.250
N15 X8.038 Y-16.700 Z40.802
省略
N5135 X336.941 Y1127.895 Z18.368
N5136 X338.718 Y1128.912 Z16.581
N5137 X340.525 Y1129.873 Z14.794
N5138 X389.067 Y1141.846
N5139 G00 Y1017.547
N5140 G00 Z0
N5141 G00 X0
N5142 G53
N5143 G00 Z0
N5144 X=P011 Y=P012
N5145 M09
N5146 M30
以上文本总行数不固定,需将前面10行与倒数第9行与倒数1-7行(红色字体)全部替换成固定内容如下:(蓝色字体)
N1 888
N2 G27 G90
N3 G00 Z0
N4 (UAO,1)
N9 M7
N10 G00 X-15.000 Z41.680
N11 X-26.078 Y-47.322
N12 X3.797 Y-20.723
N13 G01 X5.172 Y-19.499 Z41.680 F3000
N14 X6.601 Y-18.096 Z41.250
N15 X8.038 Y-16.700 Z40.802
N5135 X336.941 Y1127.895 Z18.368
N5136 X338.718 Y1128.912 Z16.581
N5137 X340.525 Y1129.873 Z14.794
N7417 G00 M10
N5139 G00 Y1017.547
N16256 G00 Z0
N16257 G00 X0
N16258 G00 Z0
N16259 G79X(@XPARK)
N16260 Y(@YPARK)
N16261 M30
求大神
作者: gaoyh2008 时间: 2019-11-13 18:17 标题: 求BAT处理,本人新手,谢谢!
%
P1394
N1 G92
N2 G90
N3 G00 Z0
N4 G09
N5 G201
N6 G202
N7 G203
N8 G54
N9 M7
N10 G00 X-15.000 Z41.680
N11 X-26.078 Y-47.322
N12 X3.797 Y-20.723
N13 G01 X5.172 Y-19.499 Z41.680 F3000
N14 X6.601 Y-18.096 Z41.250
N15 X8.038 Y-16.700 Z40.802
省略
N5135 X336.941 Y1127.895 Z18.368
N5136 X338.718 Y1128.912 Z16.581
N5137 X340.525 Y1129.873 Z14.794
N5138 X389.067 Y1141.846
N5139 G00 Y1017.547
N5140 G00 Z0
N5141 G00 X0
N5142 G53
N5143 G00 Z0
N5144 X=P011 Y=P012
N5145 M09
N5146 M30
以上文本总行数不固定,需将前面10行与倒数第9行与倒数1-7行(红色字体)全部替换成固定内容如下:(蓝色字体)
N1 888
N2 G27 G90
N3 G00 Z0
N4 (UAO,1)
N9 M7
N10 G00 X-15.000 Z41.680
N11 X-26.078 Y-47.322
N12 X3.797 Y-20.723
N13 G01 X5.172 Y-19.499 Z41.680 F3000
N14 X6.601 Y-18.096 Z41.250
N15 X8.038 Y-16.700 Z40.802
N5135 X336.941 Y1127.895 Z18.368
N5136 X338.718 Y1128.912 Z16.581
N5137 X340.525 Y1129.873 Z14.794
N7417 G00 M10
N5139 G00 Y1017.547
N16256 G00 Z0
N16257 G00 X0
N16258 G00 Z0
N16259 G79X(@XPARK)
N16260 Y(@YPARK)
N16261 M30
求大神
作者: flashercs 时间: 2019-11-13 19:50
- <#*,:&cls
- @echo off
- pushd "%~dp0"
- set "file=a.txt"
- Powershell -NoProfile -Command "$arrlines = Get-Content -ReadCount 0 -LiteralPath \"%file%\";$count = $arrlines.Count;[System.IO.File]::WriteAllLines(\"%file%\", @('N1 ;P888', 'N2 G27 G90', 'N3 G00 Z0', 'N4 (UAO,1)') + $arrlines[10..($count - 10)] + 'N7417 G00 M10' + $arrlines[-8] + @('N16256 G00 Z0', 'N16257 G00 X0', 'N16258 G00 Z0', 'N16259 G79X(@XPARK)', 'N16260 Y(@YPARK)', 'N16261 M30'))"
- popd
- pause
- exit /b
- #>
复制代码
作者: gaoyh2008 时间: 2019-11-13 20:04
回复 2# flashercs
首先谢谢您,但在执行BAT时显示Powershell不是内部命令不能执行,您能帮忙再改一下吗?
作者: zaqmlp 时间: 2019-11-13 20:51
- /*&cls
- @echo off
- set info=互助互利,支付宝扫码头像,感谢打赏
- rem 有问题,可加QQ956535081及时沟通
- title %info%
- cd /d "%~dp0"
- set "folder=#result"
- if not exist "%folder%" md "%folder%"
- dir /a-d/b *.txt|cscript -nologo -e:jscript "%~f0" "%folder%"
- :end
- echo;%info%
- pause
- exit
- */
-
-
- var a=['N1 ;P888', 'N2 G27 G90', 'N3 G00 Z0', 'N4 (UAO,1)'];
- var b=['N7417 G00 M10'];
- var c=['N16256 G00 Z0', 'N16257 G00 X0', 'N16258 G00 Z0', 'N16259 G79X(@XPARK)', 'N16260 Y(@YPARK)', 'N16261 M30'];
- var fso=new ActiveXObject('Scripting.FileSystemObject');
- while(!WSH.StdIn.AtEndOfStream){
- var line=WSH.StdIn.ReadLine();
- WSH.echo(line);
- var file=fso.GetFile(line);
- var f=fso.OpenTextFile(file.path, 1);
- var text=f.ReadAll().replace(/^\s*|\s*$/g,'').split(/\r?\n/),s=[];
- f.Close();
- var s=s.concat(a).concat(text.slice(10,-9)).concat(b).concat(text.slice(-8,-7)).concat(c);
- var f=fso.CreateTextFile(file.ParentFolder.Path+'\\'+WSH.Arguments(0)+'\\'+file.Name, 2);
- f.write(s.join('\r\n'));
- f.Close();
- }
复制代码
作者: zaqmlp 时间: 2019-11-13 21:28
回复 8# gaoyh2008
红包都没有,没动力呀
作者: gaoyh2008 时间: 2019-11-13 21:28
回复 7# zaqmlp
已解决,非常感谢!
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |