如何为包括批处理脚本令牌后空格 [英] How to include spaces after a token in batch script
问题描述
我使用的是repl.bat查找和替换文件。这里是我的code
I'm using a repl.bat to find and replace files. Here's my code
for /f "tokens=1,2" %%s in (FindNReplace.txt) do (
Type C:\user\linefeed\%%a | C:\comp\bat\repl.bat "\%%s" "%%t" X > C:\user\out\%%a
)
现在在我的FindNReplace.txt,我有样本内容:
Now in my FindNReplace.txt, I have the sample contents:
AAAAA\d{3} AAAAA
基本上包含AAAAA + 3个字节的字符串都将被AAAAA被替换。现在,如果我想要的东西,包括3个字节的空间我的字符串作为替代品使用? AAAAA + 3位我可以包括FindNReplace.txt的第二列中的特殊字符?
Basically all string containing AAAAA+3 bytes will be replaced by AAAAA. Now what if I want to include 3 bytes of spaces for my string to use as a replacement? "AAAAA+3 spaces" Can I include special character in the second column of FindNReplace.txt?
推荐答案
如果你想在你的.txt文件中的第二列的空间,你需要以指示为
命令,这些空间不应该被视为一个分隔符。简单地指示检索令牌是在该行和该第二令牌的第一个元素将是所有行中的剩余的数据。
If you want to include the spaces in the second column in your .txt file, you need to indicate to the for
command that these spaces should not be considered a delimiter. Simply indicate that the tokens to retrieve are the first element in the line and that the second token will be all the remaining data in the line.
for /f "tokens=1,*" %%s in (FindNReplace.txt) do (
Type C:\user\linefeed\%%a | C:\comp\bat\repl.bat "\%%s" "%%t" X > C:\user\out\%%a
)
和,当然也包括在第二柱的值后的三个空间。
And, of course, include the three spaces after the value in the second colum.
编辑,以适应评论
copy "C:\user\linefeed\%%a" "C:\user\linefeed\%%a.in.tmp"
for /f "tokens=1,*" %%s in (FindNReplace.txt) do (
Type "C:\user\linefeed\%%a.in.tmp" | C:\comp\bat\repl.bat "\%%s" "%%t" X > "C:\user\linefeed\%%a.out.tmp"
move /y "C:\user\linefeed\%%a.out.tmp" "C:\user\linefeed\%%a.in.tmp"
)
move "C:\user\linefeed\%%a.in.tmp" "C:\user\out\%%a"
这篇关于如何为包括批处理脚本令牌后空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!