0

I have a huge file approx 100 mb to 500 mb, it take more time to open it and I cannot change it also due to slow response in Notepad or notepad++.

I have requirement to replace only REF Number and this is only one time in the file.

Can I have a Batch file/ Script in Command prompt so that I can replace the text?

Regards and Thx.

  • 4
    To answer your question: Yes, you can if you write a batch file for this task. You might be inspired by the answers on [How can you find and replace text in a file using the Windows command-line environment?](http://stackoverflow.com/questions/60034/) You should also read the help topics about [asking](http://stackoverflow.com/help/asking) on Stack Overflow which is a site where programmers help other programmers and not a free code write service. Where is your batch code? What do you have tried so far? Take also the [2-minute tour](http://stackoverflow.com/tour). – Mofi Feb 05 '17 at 14:08
  • 2
    Answer to your question (using pure _batch-file_) depends on **1**. file **type** (format): only text files, preferably [_text/plain_ mime types](https://www.sitepoint.com/web-foundations/mime-types-complete-list/). and **2**. file **structure**: file text must be divided to _lines_ of length not exceeding some maximal value, and **3**. [file **encoding**](https://en.wikipedia.org/wiki/Character_encoding). On the other side, PowerShell is not under such strict constraints. – JosefZ Feb 05 '17 at 15:38

1 Answers1

0
@echo off
set "toreplace=REF"
for /f "tokens=* delims= " %%a in (yourfile.txt) do (
set "line=%%a"
setlocal enabledelayedexpansion
set "line=!line:%toreplace%=!"
echo !line! >>newfile.txt
)

this code deletes all REF strings from yourfile.txt and outputs it to newfile.txt.
not my code.

HackR_360
  • 192
  • 2
  • 9