![](/img/trans.png)
[英]Replace a string value from all the lines of all the text files in a directory
[英]Batch file: adding prefix to all lines of all files in a directory
我在目录D:\\ test中有文件列表,我想通过使用批处理文件在D:\\ test中的每个文件的每一行添加前缀BLA_。 完成此过程后,可以将文件移至D:\\ test \\ processed \\,并且文件名也应更改为BLA_file name。
听起来似乎并不困难,但是我没有设法创建一个有效的批处理文件。 希望可以有人帮帮我!
提前致谢!
sed的建议:
sed -i "s/^/BLA_/" D:\Test\*
for %%a in (D:\Test\*) do move "%%~a" "D:\test\processed\BLA_%%~a"
@echo off
setlocal enableextensions disabledelayedexpansion
set "inputFolder=d:\test"
set "outputFolder=%inputFolder%\processed"
for %%a in ("%inputFolder%\*"
) do (for /f "tokens=1,* delims=:" %%b in (
'findstr /n "^" "%%~fa" ^& del /q "%%~fa" ^>nul 2^>nul'
) do (echo BLA_%%c))>"%outputFolder%\BLA_%%~nxa"
endlocal
对于输入文件夹中的每个文件,读取输入文件,删除输入文件,并为所选输入文件中的每一行( findstr /n
用于避免空行跳过),将带有前缀的行回显到输出文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.