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 是否使用grep批量替换语言文件?_Batch File_Replace_Grep_Find - Fatal编程技术网

Batch file 是否使用grep批量替换语言文件?

Batch file 是否使用grep批量替换语言文件?,batch-file,replace,grep,find,Batch File,Replace,Grep,Find,我正在尝试查找/替换长语言文件: $_LANG['accountinformation'] = "Account Information"; $_LANG['accountstatistics'] = "Account Statistics"; 成为: $_LANG['accountinformation'] = "Informations du compte"; $_LANG['accountstatistics'] = "Statistiques du compte"; 知道我的

我正在尝试查找/替换长语言文件:

 $_LANG['accountinformation'] = "Account Information";
 $_LANG['accountstatistics'] = "Account Statistics";
成为:

 $_LANG['accountinformation'] = "Informations du compte";
 $_LANG['accountstatistics'] = "Statistiques du compte";
知道我的整个翻译都在这样一个文件中:

Informations du compte
Statistiques du compte

有没有办法用文本编辑器(如使用grep或其他工具的BBedit)替换这些短语,而不是手动复制/粘贴每个短语?

下面是一种使用批处理/vbs混合脚本的方法:

@echo off
setlocal

call :FindReplace "Account Statistics" "Statistiques du compte" Thefile.txt
call :FindReplace "Account Information"  "Informations du compte" Thefile.txt

exit /b 

:FindReplace <findstr> <replstr> <file>
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
  for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
    echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
    <%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
    if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
  )
)
del %temp%\_.vbs
exit /b

:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with
@echo关闭
setlocal
调用:FindReplace“Account Statistics”“Statistiques du compte”Thefile.txt
调用:FindReplace“Account Information”“Informations du compte”Thefile.txt
退出/b
:FindReplace
设置tmp=“%temp%\tmp.txt”
如果不存在%temp%\\.vbs调用:MakeReplace
对于('dir“%3”/s/b/a-d/on')中的/f“tokens=*”%%a,请执行以下操作(
对于(`Findstr/mic:'%1”“%%a`)中的/f“usebackq”%%b,请执行以下操作(
echo(&echo将文件%%~nxa中的“%~1”替换为“%~2”
%tmp%
如果存在%tmp%move/Y%tmp%“%%~dpnxa”>nul
)
)
删除%temp%\\\.vbs
退出/b
:MakeReplace
>%temp%\\.vbs与Wscript的回显
>>%temp%\\.vbs回显集参数=.arguments
>>%temp%\\.vbs echo.StdOut.Write_
>>%临时%\\ vbs回显替换(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\\.vbs回显结束

将file.txt更改为您的文件名。从文本编辑器中将脚本另存为replace.cmd,然后从命令行运行它。

如果您试图说文件是对齐的,则英文文件中每行正好有一个字符串定义,而法文则以相同的顺序包含等效翻译,每行一个,然后是一个简单的
粘贴
和一些后处理应该可以做到这一点

paste strings.def fr.txt |
sed 's/"[^"]*";\t\(.*\)/"\1";/' >output.txt

如果您的
sed
方言不支持选项卡的
\t
,那么您必须提供一个文本选项卡(在许多shell中为ctrl-v选项卡)。

您正在寻找的(我认为)是
sed
Notepad.exe“替换”(ctrl-H)“全部替换”-Button?这解决了你的问题吗?谢谢tripleee和Matt的回答:这可能对我不起作用,需要替换语言的文档有空行和行与行之间的注释,翻译的文档作为一个块提供。我希望保留原始语言的布局。