Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

string manipulation in a batch file...

19,215 views
Skip to first unread message

D'oh

unread,
Mar 25, 2001, 4:26:14 AM3/25/01
to
It is my understanding that Windows 2000 (possibly NT?) has finally
introduced some string manipulating capabilities. Do any of you know of any
good sites that give an overview/examples of this? I've searched the net
but have come up empty (which doesn't surprise me....I can't seem to find
anything anymore :).

Right now what I want to do is pretty simple (search for a substring [which
I could do right now by piping the variable to file and using find] and
possibly character/substring replacement [which I gather can be done by the
set command from reading one of the earlier posts]).


Thanks,

Greg


Outsider

unread,
Mar 25, 2001, 5:23:14 AM3/25/01
to
D'oh wrote:
>
> It is my understanding that Windows 2000 (possibly NT?)...

Windows 2000 *is* NT (version 5).
Let's keep this straight please.

--
<!-Outsider//->
MS-DOS 6.22, Windows for Workgroups 3.11, Netscape Navigator 4.08
MS-DOS 7.1, Windows 4.1 (a.k.a. 98), Netscape Navigator 4.74

Clay Calvert

unread,
Mar 25, 2001, 10:16:56 AM3/25/01
to
On Sun, 25 Mar 2001 11:23:14 +0100, Outsider
<nonvali...@yahoo.com> wrote:

>D'oh wrote:
>>
>> It is my understanding that Windows 2000 (possibly NT?)...
>
>Windows 2000 *is* NT (version 5).
>Let's keep this straight please.

In your world it is.

You can keep posting off topic questions in alt.msdos.batch, but
please refrain from posting here unless you have something beneficial
to add.


Clay Calvert
CCal...@Wanguru.com
Replace "W" with "L"

Clay Calvert

unread,
Mar 25, 2001, 10:50:03 AM3/25/01
to

SET %Var%=%Var:str1=str2% is the syntax for string replacement in NT
and Win2K.

Set WeekDay=Monday
Set WeekDay=%WeekDay:Mon=Satur%
Echo %WeekDay%

The following are examples of variable substitution and parsing in
Windows NT and Windows 2000.

A "#" character will indicate functionality only available in Windows
2000.

More information can be found from running "Set /?" and "For /?".

A "one-sided" variable is a single character variable that has a
single percent sign preceding the character.

Examples: %1 and %a


"Two-sided" variables can have more than one character and have a
percentage sign on both sides.
Examples: %temp% and %path%

%PATH:str1=str2% Substitution [: and =] Two sided only
%PATH:str1=%
%PATH:*str1=str2%

%Test:ab=xy% 123456789xycdef0
%Test:ab=% 123456789cdef0
%Test:*ab=% cdef0
%Test:*ab=XY% XYcdef0


[%:~X and %:~X,Y] Two sided variables only

The following string will be used for these examples:
set test=123456789abcdef0

Grab only the first 5 characters
%test:~0,5%
12345

Skip 7 characters and then grab the next 5
%test:~7,5%
89abc

Skip 7 characters and then grab everything else
%test:~7%
89abcdef0

Grab only the last 7 characters #
%test:~-7%
abcdef0

Grabs everything BUT the last 7 characters #
%test:~0,-7%
123456789

Grab between 7 from the front and 5 from the back #
%test:~7,-5%
89ab

Go back 7 from the end then grab 5 towards the end #
%test:~-7,5%
abcde

Grab between 7 from the end and 5 from the end #
%test:~-7,-5%
ab


[%~letter] One sided variables only

%~I removes any surrounding quotes (")
%~fI Fully qualified path name
%~dI Drive letter only
%~pI Path only
%~nI file Name only
%~xI eXtension only
%~sI Short names only
%~aI Attributes #
%~tI Time and date of file #
%~zI siZe of file #

[%~$string] Two-sided
%~$PATH:I searches the PATH and expands to the full name of the
first found

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:i - searches the PATH and expands to the drive letter and
path of the first found
%~ftzaI - expands %I to a DIR like output line #

In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.

Outsider

unread,
Mar 25, 2001, 11:50:57 AM3/25/01
to
Clay Calvert wrote:

> please refrain from posting here unless you have something beneficial
> to add.

Please follow your own advice.

Phil Robyn

unread,
Mar 25, 2001, 2:23:20 PM3/25/01
to
Clay Calvert wrote:

Great post, Clay; thanks for putting this together!

Phil Robyn
Univ. of California, Berkeley


Frank-Peter Schultze

unread,
Mar 25, 2001, 3:41:47 PM3/25/01
to
"Outsider" <nonvali...@yahoo.com> schrieb im Newsbeitrag
news:3ABDC712...@yahoo.com...

To be more correct...

Windows 2000 Professional
Windows 2000 Server
Windows 2000 Advanced Server
Windows 2000 Datacenter Server

Which Windows 2000 Is Best for You?

Quick guide to the products:
http://www.microsoft.com/Windows2000/guide/choices.asp

HTH

--
__ _ _
|_ |_)(__ http://www.fpschultze.de
___| | ____)chultze_________________________________________________
I am logged in, therefore I am.

Thorsten Kampe

unread,
Mar 25, 2001, 5:06:44 PM3/25/01
to
** Clay Calvert

>>> It is my understanding that Windows 2000 (possibly NT?)...
>>
>> Windows 2000 *is* NT (version 5).
>> Let's keep this straight please.
>
>In your world it is.

C:\> SET COMPUTERNAME
COMPUTERNAME=WIN2K01

C:\> SET OS
OS=Windows_NT


Thorsten

D'oh

unread,
Mar 25, 2001, 6:27:21 PM3/25/01
to
Yes, I'm aware that Win2k is NT5! Perhaps I should have specified NT4 or
"other versions of NT" instead of just NT but that's what I get for posting
at 4 in the morning. But that wasn't the point of my message....I was
actually trying to figure out what string manipulating capabilities were
introduced with NT. I figured that most people would be intelligent enough
to figure out what my point was instead of nitpicking.


Greg


"Outsider" <nonvali...@yahoo.com> wrote in message
news:3ABDC712...@yahoo.com...

D'oh

unread,
Mar 25, 2001, 6:30:02 PM3/25/01
to
Thank you very much!! I hadn't expected something quite so detailed
although it's greatly appreciated and it "hit the spot"!


Thanks again.


Greg

"Clay Calvert" <ccal...@wanguru.com> wrote in message
news:jv2sbtolklvai3392...@4ax.com...

Clay Calvert

unread,
Mar 25, 2001, 10:57:22 PM3/25/01
to
On Sun, 25 Mar 2001 23:30:02 GMT, "D'oh" <aa...@chebucto.ns.ca> wrote:

>Thank you very much!! I hadn't expected something quite so detailed
>although it's greatly appreciated and it "hit the spot"!
>
>Thanks again.
>
>Greg

Good, I'm glad it worked for you.

Outsider

unread,
Mar 26, 2001, 12:57:15 AM3/26/01
to
Frank-Peter Schultze wrote:
>
> "Outsider" <nonvali...@yahoo.com> schrieb im Newsbeitrag
> news:3ABDC712...@yahoo.com...
> > D'oh wrote:
> > >
> > > It is my understanding that Windows 2000 (possibly NT?)...
> >
> > Windows 2000 *is* NT (version 5).
> > Let's keep this straight please.
> >
>
> To be more correct...
>
> Windows 2000 Professional
> Windows 2000 Server
> Windows 2000 Advanced Server
> Windows 2000 Datacenter Server
>
> Which Windows 2000 Is Best for You?


Why, that would be the one that runs on Linux, of course <g>.

Clay Calvert

unread,
Mar 26, 2001, 5:36:40 PM3/26/01
to
On Mon, 26 Mar 2001 06:57:15 +0100, Outsider
<nonvali...@yahoo.com> wrote:

>Frank-Peter Schultze wrote:
>>
>> "Outsider" <nonvali...@yahoo.com> schrieb im Newsbeitrag
>> news:3ABDC712...@yahoo.com...
>> > D'oh wrote:
>> > >
>> > > It is my understanding that Windows 2000 (possibly NT?)...
>> >
>> > Windows 2000 *is* NT (version 5).
>> > Let's keep this straight please.
>> >
>>
>> To be more correct...
>>
>> Windows 2000 Professional
>> Windows 2000 Server
>> Windows 2000 Advanced Server
>> Windows 2000 Datacenter Server
>>
>> Which Windows 2000 Is Best for You?
>
>
>Why, that would be the one that runs on Linux, of course <g>.

VmWare can do this. I run it in the inverse... Linux on Windows 2000.

Outsider

unread,
Mar 27, 2001, 1:22:44 PM3/27/01
to

How about putting VmWare on a CD and sending it to me :-)?

D'oh

unread,
Mar 27, 2001, 3:33:21 PM3/27/01
to
> How about putting VmWare on a CD and sending it to me :-)?

You can download it at www.vmware.com


Clay Calvert

unread,
Mar 27, 2001, 8:01:37 PM3/27/01
to
On Tue, 27 Mar 2001 19:22:44 +0100, Outsider
<nonvali...@yahoo.com> wrote:

>Clay Calvert wrote:
>>
>> On Mon, 26 Mar 2001 06:57:15 +0100, Outsider
>> <nonvali...@yahoo.com> wrote:
>>
>> >Frank-Peter Schultze wrote:
>> >>
>
>> >> Which Windows 2000 Is Best for You?
>> >
>> >
>> >Why, that would be the one that runs on Linux, of course <g>.
>
>> VmWare can do this. I run it in the inverse... Linux on Windows 2000.
>>
>
>How about putting VmWare on a CD and sending it to me :-)?

You realize that the version that I bought requires NT or Win2K. I
did not buy the Linux version.

The minimum requirements are:

- 266MHz or faster processor
- RAM, Minimum: 96MB; recommended: 128MB
- At least 500MB free disk space recommended for guest operating
systems and applications.

If you still want it, let me know.

Outsider

unread,
Mar 28, 2001, 3:52:35 AM3/28/01
to
Clay Calvert wrote:
>
> On Tue, 27 Mar 2001 19:22:44 +0100, Outsider
> <nonvali...@yahoo.com> wrote:

> >>
> >
> >How about putting VmWare on a CD and sending it to me :-)?
>
> You realize that the version that I bought requires NT or Win2K. I
> did not buy the Linux version.

No, I hadn't realized that.



> The minimum requirements are:
>
> - 266MHz or faster processor
> - RAM, Minimum: 96MB; recommended: 128MB
> - At least 500MB free disk space recommended for guest operating
> systems and applications.
>
> If you still want it, let me know.

No. Thanks :-), but I don't think I can use that version.

http://www.vmware.com/support/reference/common/guest_dos.html

I could use a version that supports DOS 6.x, DOS 7.x/Win9.x and Linux.

Clay Calvert

unread,
Mar 28, 2001, 9:23:03 AM3/28/01
to
Thorsten Kampe <thorste...@web.de> wrote in message
news:99lq5k$1nl1g$1...@ID-77524.news.dfncis.de...

MSD.exe says that the operating system is MS-DOS 5.5.

Can you name an operating system based on mechanisms used for backwards
compatiblity?


Clay Calvert

unread,
Mar 28, 2001, 8:55:00 AM3/28/01
to
Outsider <nonvali...@yahoo.com> wrote in message
news:3AC1A653...@yahoo.com...

> Clay Calvert wrote:
> >
> > On Tue, 27 Mar 2001 19:22:44 +0100, Outsider
> > <nonvali...@yahoo.com> wrote:
>
> > >>
> > >
> > >How about putting VmWare on a CD and sending it to me :-)?
> >
> > You realize that the version that I bought requires NT or Win2K. I
> > did not buy the Linux version.
>
> No, I hadn't realized that.
>
> > The minimum requirements are:
> >
> > - 266MHz or faster processor
> > - RAM, Minimum: 96MB; recommended: 128MB
> > - At least 500MB free disk space recommended for guest operating
> > systems and applications.
> >
> > If you still want it, let me know.
>
> No. Thanks :-), but I don't think I can use that version.
>
> http://www.vmware.com/support/reference/common/guest_dos.html
>
> I could use a version that supports DOS 6.x, DOS 7.x/Win9.x and Linux.

Hmm? VmWare does support all of those.

I can see why it would be a problem for you since you use emm386, but the
other OSes you listed run just fine.

0 new messages