Re: DOS Batch File Question

  • From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 2 Jul 2010 08:37:31 +0100

Thank you Laura,

I should mention that Google can be very helpful in this area. Because Microsoft finds it so difficult to pitch their help files at the correct level, there is a colossal amount of explanatory stuff on the internet. Use search words such as DOS, command line, command.com, cmd.exe, and batch files, but bear in mind that the language has changed significantly over time, so check for cobwebs on the pages you read. In fact I forgot to mention to Don that I am running 32-bit XP here, so some of my formulations might need breathing on for someone with a 21st century operating system.

 Martin


----- Original Message ----- From: "qubit" <lauraeaves@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, July 02, 2010 3:24 AM
Subject: Re: DOS Batch File Question


this is interesting for those of us who know unix shell programming but
never got into dos. Thanks. This answers some curiosities I have had when I
have had the necessity of fiddling with dos.
That isn't now, but next time I need it i'll know a little more.
Happy hacking.
--le

----- Original Message ----- From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 1:59 PM
Subject: Re: DOS Batch File Question


 This is the batch file I use (called remove.bat) to remove a line which
matches a string command line parameter:

@echo off
findstr /I /L /V "%1" phones.txt > temp
erase phones.txt
ren temp phones.txt

 So I call remove testString from a command line which can see the batch
file. I usually don't include spaces in the testString, but surrounding the
parameter with double quotes might get that to work.

 phones.txt is my target file.  You might want that filename to be a
parameter too.

 There is absolutely no error checking here, so I usually run a
non-inverted findstr command first that just prints out the matches.  My
goal is always to fiddle the testString to give only one match, since I only
want to remove one line at a time.  If I get more than one match, I try
again.

 It would definitely be safer to include the checking stage in the same
batch file, so something like this might be called for:

@echo off
findstr /I /L "%1" phones.txt
set reply=""
set /p reply=Continue? (y/n):
if "%reply%"=="n" (exit /b)
findstr /I /L /V "%1" phones.txt > temp
erase phones.txt
ren temp phones.txt

 This seems to work (with about five minutes of checking.  Let me know how
you get on.

 Martin



----- Original Message ----- From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 2:01 PM
Subject: Re: DOS Batch File Question


I would appreciate looking at your code.  I started putting that exact
approach together late last night and could not quite get it to work.

I also have a ugly solution using a for /f statement combined with a find
statement and the ancient edlin commands.  The edlin command only works
with short filenames!

Don Marang

--------------------------------------------------
From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 2:23 AM
To: <programmingblind@xxxxxxxxxxxxx>
Subject: Re: DOS Batch File Question

Hi Don,

To do what you want in a DOS batch file, you need to use find or findstr to pull out the lines you want to remove. Those functions have an option
to invert the selection so you can redirect the output, minus the chosen
lines, into a temporary file. Then append the new line to that file, and
finally rename it to overwrite the original file (or not) as you prefer.

 I'm doing something like this myself.  Let me know if you need code
samples and I'll dig them out.

 Martin


----- Original Message ----- From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 4:05 AM
Subject: DOS Batch File Question


I was attempting to help someone write a batch file to help configure
VMware Player to use a preconfigured Vinux Virtual Machine.  We want to
modify the %AppData%\VMware\preferences.ini file to set the hotkey
combination to Alt + Control + Shift.  To do this, I need the batch file
to do two things.

1.  Delete  any lines that contain the word "hotkey" that are currently
in the file.  Two definitions are not permitted in this file.  There are
other similar lines that appear in this file, but only this line seems to
be processed in the newest versions of the software.

2.  Append a line at the bottom of the file to define the desired hotkey
with the command:
echo 'pref.hotkey.shift="true"' >> %AppData%\VMware\preferences.ini

Obviously, I know how to get the second task done.  Can anybody help me
with the first? We would need it to work in XP, Vista and Windows 7. In
Linux, I think a simple sed statement would do the trick, like
sed 'hotkey/d' ${AppData}/VMware/preferences.ini

I am just guessing at the above hypothetical syntax as well.  I have not
attempted anything like that in years.Does anybody know how to modify
text files in DOS?  I ran across 'munge', which could have accomplished
this as long as an additional definitions file was used.  I use the past
tense since it has not been around for a long time.  There must be some
such capability to search and destroy! The 'FIND' command can locate the
lines.  I want them deleted as well.

Don Marang
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: