`

Replace text in file

阅读更多

 

Windows

 

@echo off

if %1%.==. (
  echo Usage: %0% FILE_FULL_PATH SOURCE_STRING DESTINATION_STRING
  echo Where: FILE_FULL_PATH is the full path of the file to be replaced in
  echo        SOURCE_STRING is string to be replaced
  echo        DESTINATION_STRING is string to be replaced as
  pause 
  exit
)

if %2%.==. (
  echo Usage: %0% FILE_FULL_PATH SOURCE_STRING DESTINATION_STRING
  echo Where: FILE_FULL_PATH is the full path of the file to be replaced in
  echo        SOURCE_STRING is string to be replaced
  echo        DESTINATION_STRING is string to be replaced as
  pause 
  exit
)

if %3%.==. (
  echo Usage: %0% FILE_FULL_PATH SOURCE_STRING DESTINATION_STRING
  echo Where: FILE_FULL_PATH is the full path of the file to be replaced in
  echo        SOURCE_STRING is string to be replaced
  echo        DESTINATION_STRING is string to be replaced as
  pause 
  exit
)

setlocal enabledelayedexpansion 

set file=
rem set /p replaced= Please input the file full path: 
set "file=%1%"
for %%i in ("%file%") do set file=%%~fi 
echo. 

set replaced= 
rem set /p replaced= Source String: 
set "replaced=%2%"  
echo. 

set all= 
rem set /p all= Destination String: 
set "all=%3%"
echo.

for /f "delims=" %%i in ('type "%file%"') do ( 
  set str=%%i 
  set "str=!str:%replaced%=%all%!" 
  echo !str!>>"%file%".tmp 
) 

copy "%file%" "%file%".bak >nul 2>nul 
move "%file%".tmp "%file%" 
rem start "" "%file%" 

 

 

Linux

 

sed -in-place -e 's/old/new/g' text.txt

分享到:
评论

相关推荐

    replace-in-files-cli:替换文件中匹配的字符串和正则表达式

    $ npm install --global replace-in-files-cli 用法 $ replace-in-files --help Usage $ replace-in-files Options --regex Regex pattern to find (Can be set multiple times) --string String to find ...

    Galcott.Super.Text.Search.v3.13-BEAN

    In plain ASCII text files it also allows you to replace text. You can search anything from a single file to an entire drive for any text you need to find. Both plain text files (program source code, ...

    replace-in:替换给定文件中的文本

    npm install replace-in 这个怎么运作? 它创建一个读取流以分块的形式从目标文件中读取。 替换每个请求并使用写入流写入结果。 更换完成后,将返回最终报告。 原料药 替换(选项) options对象包含: path: ...

    UE(官方下载)

    The benefit of a column maker is that it can help you to format your text/code, or in some cases to make it easier to read in complex nested logic. Quick Open UltraEdit and UEStudio provide multiple ...

    Sublime Text 3 (Build 3143)

    Find in Files panel now responds to find_all and replace_all commands Various regex handling improvements in the Find panel Fixed text widgets cutting off the bottom pixel of their selection border ...

    强大的免费的十六进制编辑器

    - Replace text or hex string, e.g. replace "0D 0A" by "0A" or replace "0D 0A" by text "EOL" - Extremely fast "replace all" mode (if needed, additional memory is allocated beforehead, not at every ...

    plug-In PHP- 100 Power Solutions

    Upload File; Resize Image; Make Thumbnail; Image Alter; Image Crop; Image Enlarge; Image Display; Image Convert; GIF Text; Image Watermark; Relative to Absolute URL; Get Links from URL; Check Links; ...

    Sublime Text Build 3124 x64 Setup.exe

    Fixed Replace not working as expected in conjunction with regex look behinds Fixed build systems being unable to use "file_patterns" with the exec command Corrected tab overlap on HiDPI Windows and ...

    Oracle P/L SQL实现FTP上传、下载功能

    ai_LocalFilename in out Nocopy UTL_File.File_Type, as_TransferMethod in VarChar2 Default Null ); Procedure p_GetFileList( ac_Connection in out Nocopy Connection, afl_List out ...

    Python替换不了word中的文字?.zip

    以下是一个简单的示例,展示了如何使用python-docx库在Word文档中替换文字: python复制代码运行from docx import Documentdef replace_text(old_text, new_text, file_path): # 打开文档 doc = Document(file_path)...

    TMS Pack for FireMonkey2.3.0.1

    Fixed : Issue with text initialization in constructor in TTMSFMXGrid Fixed : Issue with default values for ArrowHeight and ArrowWidth in TTMSFMXPopup Fixed : Issue with focusing calendar in ...

    Practical Vim: Edit Text at the Speed of Thought

    It's available on almost every OS--if you master the techniques in this book, you'll never need another text editor. Practical Vim shows you 120 vim recipes so you can quickly learn the editor's core...

    SEBS47-计算蒸散发_蒸散发_sebs_SEBS47-计算蒸散发_batch_

    In 'c:\sebs47\' you can find the file 'envi.men' (text file).4. With the file 'envi.men' in 'c:\sebs47\' replace the file 'envi.men' under 'c:\rsi\idl60\products\envi40\menu\'.5. Start ENVI4.06. on ...

    npp.8.0.Installer.x64.exe

    21. Fix regression: Handle "Default Directory" setting correctly in Open/Save File Dialog. 22. Fix a special character in UTF16 file crash issue 23. Add "Append extension" checkbox to Save As dialog. ...

    npp.8.0.portable.x64.7z

    21. Fix regression: Handle "Default Directory" setting correctly in Open/Save File Dialog. 22. Fix a special character in UTF16 file crash issue 23. Add "Append extension" checkbox to Save As dialog. ...

    npp.8.0.portable.x64.zip

    21. Fix regression: Handle "Default Directory" setting correctly in Open/Save File Dialog. 22. Fix a special character in UTF16 file crash issue 23. Add "Append extension" checkbox to Save As dialog. ...

    Java文件处理工具类--FileUtil

    // Replace invlid chars: \\/:*?\"| switch (ch) { case '\\': case '/': case ':': case '*': case '?': case '\"': case ' case '>': case '|': out.append('_'); ...

    文件对比工具 ExamDiff

    ExamDiff Pro provides a simple means of performing visual file and folder comparisons in Windows. It's attractive, easy to use, and offers the tools you need to do the job quickly and thoroughly. It ...

    Senfore_DragDrop_v4.1

    A batch file, convert_forms_to delphi_4_format.bat, is supplied in the demo directory which automates the conversion process. The C++ Builder demo forms are distributed in binary format. 7) If ...

    Oracle P/L SQL实现发送Email、浏览网页等网络操作功能

    as_MimeType in VarChar2 Default 'text/plain', as_ContentID in VarChar2 Default Null, -- ab_Inline in Boolean Default False --True将文本内容直接在邮件内容显示出来,并出现在附件中,False...

Global site tag (gtag.js) - Google Analytics