English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I would like an MS-DOS batch file that asks the user to type in some text and then put that text into several other files instead of a specific peice of text in those other files.

For example, if I have 3 files named file1.txt, file2.txt and file3.txt respectively, each containing a chunk of text, somewhere in which is the word DEFAULT_WORD, I would want this batch to take in a word or words from the user - for example NEW WORDS - and then replace every occurence of DEFAULT_WORD with NEW WORDS in all three of the text files.

Can answerers please leave the code in their answer and I will then put this in a batch and test it. The best working batch will win the best answer. Also, explainations of anything unusual or complex in the code would be greatly appreciated (but entirely optional).

2006-09-16 04:10:32 · 3 answers · asked by Rich 5 in Computers & Internet Programming & Design

Well psstthok, if its so simple then I'm sure it wouldn't have been too much bother for you to actually answer my question.

2006-09-16 04:36:44 · update #1

To linen: you seem to know what you're talking about, but I'm not so keen on having to install extra software for this to work; I'd rather a batch that would work on a machine that has (and shall have) no extra software installed.

2006-09-16 04:40:17 · update #2

3 answers

Assuming you can install PERL:

you can put the following into a batch-file:


@echo off
perl -0ni.old -e "s/^(.{offset})searchtext/\1replacement/;print;" %1
rem remove this to keep the original file
del %1.old
goto end

:error
echo Usage foo.bat [filename]
:end

change offset, searchtext and replacement to your needs.

2006-09-16 04:18:46 · answer #1 · answered by linen 2 · 0 0

There is not an inherent dos command that will do this. But there is a unix command called fgrep that you could download and run in DOS to do it. Otherwise, this would be a pretty simple cscript/wscript script to write.

2006-09-16 12:31:48 · answer #2 · answered by sethsdadiam 5 · 0 0

what you are describing is very simple if you understand computers, go do your homework and here are some keywords for you to google:

AWK, SED and VI.

these all run under Unix which is an operating system - BATCH files run under dos/windows, which is an adult toy. (hold that mental image, ppl - where would YOU put an adult toy?)

2006-09-16 11:16:54 · answer #3 · answered by Anonymous · 0 1

fedest.com, questions and answers