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
Batch file 编辑文件的批处理脚本_Batch File - Fatal编程技术网

Batch file 编辑文件的批处理脚本

Batch file 编辑文件的批处理脚本,batch-file,Batch File,我有一个包含以下内容的文件- SF:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\Greeter.js DA:1,2 DA:4,2 DA:5,2 end_of_record SF:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\GreeterTest.js DA:1,2 DA:3,2 DA:4,2 end_of_record 我需要一个批处理脚本,将所有出现的“D:\Saurabh\Work\WS\devic

我有一个包含以下内容的文件-

SF:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\Greeter.js
DA:1,2
DA:4,2
DA:5,2
end_of_record
SF:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\GreeterTest.js
DA:1,2
DA:3,2
DA:4,2
end_of_record
我需要一个批处理脚本,将所有出现的“D:\Saurabh\Work\WS\devicehowto.war\scripts.\”替换为空格字符。因此,在运行批处理脚本之后,内容应该如下所示-

SF:Greeter.js
    DA:1,2
    DA:4,2
    DA:5,2
    end_of_record
    SF:GreeterTest.js
    DA:1,2
    DA:3,2
    DA:4,2
    end_of_record
请帮忙。 谢谢

生成new.txt

不确定第二行和后续行缩进的原因。如果这是故意的,请指定标准。

干得好


这些答案可能会有帮助:非常感谢Peter。这很好用。只有一件事。我们是否可以更新同一个文件,而不是在new.txt中写入输出?不合适。只要
move/y new.txt saurabh.txt
即可,其中
类型
非常完美。非常感谢,彼得。这正是我想要的。
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
(
FOR /f "delims=" %%i IN (saurabh.txt) DO (
 SET "line=%%i"
 SET "line=!line:D:\Saurabh\Work\WS\devicehowto.war\scripts\.\=!"
 ECHO(!line!
)
)>new.txt
TYPE new.txt
GOTO :eof
sed "/SF/s/:.*\\/:/" saurabh.txt