Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何使程序正确运行_Batch File_Cmd - Fatal编程技术网

Batch file 如何使程序正确运行

Batch file 如何使程序正确运行,batch-file,cmd,Batch File,Cmd,此程序用于反转文件out1.txt中的所有字符串 做错了。在result.txt中,我发现最后输入的字符串错误020701BT,后面是 020701BT 如何正确反转文本文件 @echo off setlocal enabledelayedexpansion set I=0 for /F "tokens=*" %%k in (out1.txt) do ( set /A I=!I! + 1 set LINE!I!=%%k ) for /L %%c in (!I!,-1,1) do

此程序用于反转文件out1.txt中的所有字符串 做错了。在result.txt中,我发现最后输入的字符串错误020701BT,后面是 020701BT

如何正确反转文本文件

@echo off
 setlocal enabledelayedexpansion

set I=0

for /F "tokens=*" %%k in (out1.txt) do (
  set /A I=!I! + 1
  set LINE!I!=%%k
)

for /L %%c in (!I!,-1,1) do (
echo !LINE%%c! >> result.txt
)
out1.txt-输入文件

020701BT

<>710f7fa45c6911e9648d2cfda1bf577d

020701BT

<>cde9bde81a5b11e96b882cfda1bf577d

020701BT

<>d266b9021a5b11e96b882cfda1bf577d

040109GT

result.txt输出文件结尾有错误

<>cde9bde81a5b11e96b882cfda1bf577d

020701BT

<>710f7fa45c6911e9648d2cfda1bf577d

020701BT

020701BT

根据您的解释(而不是您的代码),您似乎只想去掉
之间的两个字符

所以这个答案是基于这一点,而不是你的代码,因为这似乎是不同的东西

我们可以使用正则表达式通过
findstr
实现这一点,删除字符并再次缝合字符串

@echo off
set "inputfile=goods.xml"
for /f "tokens=1,* delims=>" %%i in ('findstr /R "<frame>[0-9a-F][0-9a-F]/[^/]*" "%inputfile%"') do (
   set reg=%%j

for /f "tokens=*" %%a in ('type "%inputfile%" ^| find /v /n "" ^& break ^> "%inputfile%"') do (
     set "str=%%a"
     call set "str=%%str:*]=%%"
     setlocal enabledelayedexpansion
     if "!str!" == "%%i>!reg!" ( 
          set "reg=!reg:*/=!"
          set "str=%%i^>!reg!"
       )
     >>%inputfile% echo(!str!
    endlocal
   )
)
@echo关闭
设置“inputfile=goods.xml”
对于/f“tokens=1,*delims=>”%%i in('findstr/R“[0-9a-f][0-9a-f]/[^/]*”“%inputfile%”)do(
set reg=%%j
对于('type”%inputfile%%“^ find/v/n”“^&break^>%inputfile%”中的/f“tokens=*”%%a,请执行以下操作(
设置“str=%%a”
调用集“str=%%str:**]=%%”
延迟扩展
如果“!str!”==”%%i>!reg!”(
设置“reg=!reg://=!”
设置“str=%%i^>!reg!”
)
>>%输入文件%echo(!str!
端部
)
)

而Gerhard Barnard的答案有效(将输出重定向到新文件后)
一般来说,XML文件应该用XML工具处理

我建议使用带有正则表达式的PowerShell脚本

RE的优点是它独立于位置工作,只需要定义的前缀/后缀

主题包装在cmd行/批中

powershell -NoP -C "(Get-Content .\goods.xml -raw) -replace '(?<=\<frame\>)..(?=/)'|Set-Content .\goods.xml"

powershell-NoP-C“(获取内容。\goods.xml-raw)-replace”(?因此,您的预期输出类似于
/592582ae03011e6e19f141877341409
?您发布的代码与您描述的任务有什么关系?您似乎没有自己尝试解决它。请阅读帮助文章和!提示:首先将的选项字符串修改为
tokens=1-4 delims=>/
…@Vitalylegovich,我已将您的问题回复到您最近编辑之前的状态。您的编辑创建了一个完全不同的问题,虽然已关闭,但无法发布新答案。由于您已对问题进行了全部更改,会员不太可能投票重新打开您的问题。请阅读,尤其是作为answe的一员rs完全符合您的问题要求。然后创建一个新问题,如果您希望获得有关其他问题/任务的帮助。我更新我的问题,请回答我的问题如何更改文件内容,如何更改文件内容,您只在屏幕上编程更改,而不在文件上编程。请是指内容保存到文件如何更改文件内容。xml?,您只能在屏幕上编程更改信息,而不能在文件中编程更改信息。please@vitalyolegovich请参阅有关回写文件的编辑版本。+1;此答案应适用于提出的问题,即使在给出答案后对其进行了修改。不过,请注意,
-Raw
参数之前需要删除,但doing so不应引起任何实际问题。