1752798 Members
5663 Online
108789 Solutions
New Discussion юеВ

Re: DOS help

 
SOLVED
Go to solution
Steven Chen_1
Super Advisor

DOS help

This is a repost hoping to get some quick soul helps:

---------------------
Hi,

Somehow I switch from Unix scripting to DOS batch command and need help here:

how to replace a word in a text file, such as "DEVPLOP" to "PRODUCTION", multiple times and save the file, either with original name or different name.

Unix script makes it simple, but DOS command seems to be remote to me.


Any help is appreciated!

Steven
Steve
20 REPLIES 20
Robert-Jan Goossens
Honored Contributor
Solution

Re: DOS help

Hi Steven,

cmd edit "open file" / "search and replace"

Robert-Jan
spex
Honored Contributor

Re: DOS help

Hi,

sed for DOS is available here:

http://www.student.northpark.edu/pemente/sed/

PCS
Chan 007
Honored Contributor

Re: DOS help

Hi,

If you are using a windows system for doing your DOS edit stuff, open the file in "notepad"

then you find under the edit menu, "replace" type in what you wanted to. Also note if you need to enable/disable the match case.

Chan
Steven Chen_1
Super Advisor

Re: DOS help

I want a batch command, not doing it manually using notepad or ed utility, such as sed or awk doing text edition in an easy way.

Any help is appreciated!
Steve
spex
Honored Contributor

Re: DOS help

Steven,

1) Download sed for DOS:
http://www.student.northpark.edu/pemente/sed/ssed360s.zip

2) Extract sed-3.59.exe to a directory in %PATH%.

3) Rename sed-3.59.exe to sed.exe.

4) cd

5) sed 's/DEVELOP/PRODUCTION/g' < textfile > textfile.new

PCS
Yogeeraj_1
Honored Contributor

Re: DOS help

hi steven,

one workaround would be to send the text file to a unix machine, do the change and get it back.

of course, it will be easy if and only if it is a once off task.

hope this helps too!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
A. Clay Stephenson
Acclaimed Contributor

Re: DOS help

Let me suggest a Plan B that will work in either a UNIX or a Windows environment -- Perl. You can install one of the free Perl's for Windows (e.g. www.activestate.com) and then your scripts (if well written) will work in both worlds without changes.
If it ain't broke, I can fix that.
Steven Chen_1
Super Advisor

Re: DOS help

A. Clay,

I want to try Plan B. Do you have syntac handy so that I can jump right ahead?

Thanks,

Steven
Steve
A. Clay Stephenson
Acclaimed Contributor

Re: DOS help

Sure, and this will make an automatic backup file for you named filename.save where filename is the original source file.

perl -i.save -p -e 's/DEVPLOP/PRODUCTION/g' file1 file2 ...

It will process each file listed and create a backup file1.save, file2.save, ... the modified files will be file1, file2, ...

If you don't want the backup files then omit the -i option.
If it ain't broke, I can fix that.