[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

Batch files

Hi,

I have a batch file that has a the string test.txt file inside..

I want to within another batch file open this batch file up and change all instances of the test.txt to 1234.txt etc. I need a bit of user interaction i.e to add the number that will replace the "test"

Is there anyway to do this? I know that I can use the find to get the string but where do I go from here. I am  using DOS 6.2 and cannot add anything else to the machine so it needs to work in a batch file.

Any ideas how I can replace this?

many thanks in advance.

Points are high as I need this quite quickly.

Cheers

K
;)
0
Kartibok
Asked:
Kartibok
  • 5
  • 4
  • 4
  • +4
3 Solutions
 
SteveGTRCommented:
Given the constraints, DOS 6.2 and no additions, I have no solution.
0
 
CaudaxCommented:
I'll see if I can come up with a feasible solution later. I'm fairly certain it's doable without using any programs that DOS 6.22 doesn't already include.

Could you post the batch file you would like edited or a sample batch file that functions similarly? Thank you.
0
 
PaulCaswellCommented:
Hi Kartibok,

A couple of ideas:

1. Build a third batch file that contains stuff like the following where %1 is where the 'test.txt' or '1234.txt' should appear.:

...
ECHO COPY %1 AFILE.TXT >>NEWBATCH.TXT
...

Then execute this batch with parameter '1234.txt' or 'test.txt', then execute NEWBATCH.BAT.

2. Split the batch fiile up into pieces and create one file containing 'test.txt' and another containing '1234.txt'.

Again, build the final batch out of the parts using COPY /B PART1 + filename + PART2 + filename + .....

Not clear? Post a sample of your batch file and we can construct the two forms an see which would be bet for you.

Paul
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
For-SoftCommented:
There is an EDIT.COM editor in the DOS 6.2. You can change all instances of a string to some other string in it. But you have to do it manualy.
0
 
PaulCaswellCommented:
I've seen some hacks/interesting methods that use DEBUG to build a tiny program in assembler to do relatively simple things on the fly. If we could then enumerate each line from the batch file as a parameter to this tiny assembler coded program that just replaces a fixed string with another in the command line and prints the result we have the beginnings of something.. Could that be the way to a solution?

How important is it that we cant add anything to the system and how strict are the rules on this one? There are many freeware search-and-replace tools available that are stable and reliable and 16bit and small-footprint! I could write one myself in a few hours.

Are there any dos extensions in there already like BATEN perhaps?

Paul
0
 
KartibokAuthor Commented:
I have a number of users who are running dos machines and require a batch file to update their antivirus editions.

I just wanted a simple batch file, which I have that lets them install norton AV for dos and then adds a few other batch files that help update and then check CDs and fdds.

I need to know what machines are done so I create a txt file that produces a serial number txt file.

From here I was hoping to amend the file in a message box input type entry but I know that is not available in DOS. The only input I know is when they choose selections.

I will put the file on tomorrow as it is at work.

I cannot put anything on these machines except dos so it looks like the user may have to edit the batch file afterall!

many thanks for the help everyone.

K
;)
0
 
Steve KnightIT ConsultancyCommented:
The only pure DOS text entry I know of is

COPY CON textfile.txt

which you have to end with Control Z enter (or F5 enter)

I did wonder if you could redirect standard in to EDIT.COM with a textfile of instructions, i.e.
edit xyz.txt < test.txt

Control Q A (replace dialog), search string TAB replace string etc...
but it seems to ignore the redirected input so no good.

Do you have edlin available on there.  I seem to remember there was a replace command in there that might be able to take a redirect like above?

How about rather than creating a serial number it appends a line to autoexec like set serialnum=xxxxxx then you check it later with %serialnum%?

Steve
0
 
KartibokAuthor Commented:
Here is the file. There are other parts but I want to change the test text as mentioned before.
:: Scans for exe files
:SCAN
CD C:
DIR *.EXE /S >> C:\test.TXT
@ECHO ***** SCAN COMPLETE *****
COPY C:\test.TXT A:\
EXIT

Any ideas?

K
;)
0
 
For-SoftCommented:
What about renaming the TEST.TXT file to 1234.TXT afterwards.
It would be simple task to add a rename command at the beginning or at the end of the batch file.
Running the rename command rfom other batch file would be a help, as well.

You can replace the whole batch file during AV software update update, also.

Finally: you can add a second :SCAN labelled section at the begin of the batch file. It should be run instead of the old one, because it would be the first occurence of the :SCAN label.
0
 
PaulCaswellCommented:
Hey! Hang-on ... isnt edlin still around? Check would you? If so we could do it with that!

I just created a file called edcmd.txt containing:

1,10000r1^Z2
e

The ^Z must be an actual Ctl-Z or hex 1a.

I then did:

edlin junk.txt<edcmd.txt

and it replaced every '1' in the file with a '2'.

Should work!

Paul
0
 
PaulCaswellCommented:
Getting user input is another matter and I agree that 'copy con' is the only raw dos option you have. The user will have to enter F6 to complete the entry.

Paul
0
 
For-SoftCommented:
No. There is no EDLIN file in the DOS 6.2
0
 
PaulCaswellCommented:
Thats odd! It was introduced way back in the early days and its still available in XP!

Ah well! Cest La Vie!

Paul
0
 
Steve KnightIT ConsultancyCommented:
Yes but edlin is an external command so depends upon being available on the particular machine...

How are you currently creating the serial number to replace, does it exist anywhere.  Sounds like the best bet would be to run the batch file with a paramater, i.e. have the user type

batfile 1234

REM BATfile.bat
:: Scans for exe files
:SCAN
CD C:
DIR *.EXE /S >> C:\%1.TXT
@ECHO ***** SCAN COMPLETE *****
COPY C:\%1.TXT A:\
EXIT


Steve
0
 
KartibokAuthor Commented:
I don't have edlin on the system, and the serial number is the one that comes from Dell or what ever manufacturer we buy the stuff from.

I'm afraid I can't see how I could get the user to add the details at the moment. I don't mind the engineers doing it as they should have an understanding of edit but I was just trying to make it a bit easier.

It looks like I will set the main batch file to open the update.bat so it can be amended.

K
;)
0
 
Steve KnightIT ConsultancyCommented:
OK, how about this.  Run your batch file then something like:


prompt Now type go followed by the serial number, e.g.  GO ABC1234:

Then have a file go.bat as follows:

if "%1"=="" echo you need to enter a serial number, e.g. GO ABC1234
if "%1"=="" goto end
promtp $p$g
:: Scans for exe files
:SCAN
C:
CD \
DIR *.EXE /S >> C:\%1.TXT
@ECHO ***** SCAN COMPLETE *****
COPY C:\%1.TXT A:\
:end
0
 
Steve KnightIT ConsultancyCommented:
Kartibok,

Have you tried any of the above?

Steve
0
 
RkMishraCommented:
You can use external DOS utilities which are available on net.
Try Google and download following tools.
For user input :   ENVPUT.COM
for string alteraion:   XCHANGE.EXE or ALTER.EXE
Now put them in a 2nd batch file with following command:

@echo off
ENVPUT "Number to replace" no
rem Variable set no=<input>
xchange 1stbat.bat "texs.txt" "%no%.txt"
call 1stbat.bat
 
(XCHANGE.EXE is a Clay Ruth's Batch enhancement tool)
0
 
KartibokAuthor Commented:
Sorry about the delay. I have been unable to try some of the ideas. I will try them after Easter and get back to people. Many thanks for your patience.

K
;)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 4
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now