Batch file 编辑2500个文本文件,在@x之后添加整数和小数的三位小数*

Batch file 编辑2500个文本文件,在@x之后添加整数和小数的三位小数*,batch-file,Batch File,有2500个文本文件需要检查,并在@x*之后加上小数位数 例如: @x*1 pcs (result should be @x*1.000 pcs) @x*1.2 pcs (result should be @x*1.200 pcs) @x*1.25 pcs (result should be @x*1.250 pcs) @x*1.238 pcs (result should be @x*1.238 pcs) @x*1.2897 pcs (result should be @x*1.299 pcs

有2500个文本文件需要检查,并在@x*之后加上小数位数

例如:

@x*1 pcs (result should be @x*1.000 pcs)
@x*1.2 pcs (result should be @x*1.200 pcs)
@x*1.25 pcs (result should be @x*1.250 pcs)
@x*1.238 pcs (result should be @x*1.238 pcs)
@x*1.2897 pcs (result should be @x*1.299 pcs)

enter code here
简单使用正则表达式文本处理实用程序,再加上一点自定义JScript。我使用了在中描述的方法来可靠地对十进制值进行四舍五入。如果没有它,像0.0008这样的值将不正确地四舍五入到0.000

@echo off
for %%F in (*.txt) do call jrepl "(@x\*)(\d+\.?\d*|\.d+)" "$1+Number(Math.round($2+'e'+3)+'e-'+3).toFixed(3)" /j /f "%%F" /o -
编辑:添加示例


你应该在这里输入你的代码,而不是
在这里输入代码。如果我假设你的帖子有原始的输入文本,你希望输出文本是什么样的?请发布您尝试过的代码。为什么1.2897四舍五入为1.299?不是应该是1.290吗?是的,阿奇尼,应该是1.290。我测试了这些代码。这段代码中有一个问题,我无法解决。我只想编辑“@x*”后面的数字。对其他数字不应有任何影响。我在等待你们的帮助。我恐怕不理解你们的担心。请参阅我的答案中的编辑:数据和结果与您在问题中发布的完全相同!这是我要编辑的文件。在那里你可以看到@x*和之后的数字。我只想编辑那些数字。材料:SLL040083,蒸山毛榉32x40x830毫米@X*0.0161件或@X*0.0134 MS-每件62件。翻录:宽度:18毫米。此订单所需金额:@X*0.0268毫秒。多刀片厚度:按计划32毫米。锯条:宽度:25毫米。此订单所需金额:@X*0.0268毫秒。四边厚:14毫米。
@echo off
setlocal EnableDelayedExpansion

rem Process the 2500 text files
for %%f in (*.txt) do (
   rem Process this file:                 load it, then delete it
   for /F "tokens=1-3 delims=. " %%a in ('type "%%f" ^& del "%%f"') do (
      rem Get current decimal part
      if "%%c" equ "" (set b=0000) else set "b=%%b000"
      rem Round it to three digits
      set /A b=1!b:~0,4!+5
      rem And write it
      echo %%a.!b:~1,3! pcs>> "%%f"
   )
)
C:\> type test.txt
@x*1 pcs
@x*1.2 pcs
@x*1.25 pcs
@x*1.238 pcs
@x*1.2897 pcs

C:\> test.bat

C:\> type test.txt
@x*1.000 pcs
@x*1.200 pcs
@x*1.250 pcs
@x*1.238 pcs
@x*1.290 pcs