Edit Text of a Text-based File by Using Batch

Microsoft Windows xp pro with sp3 multil...
January 15, 2010 at 19:41:52
Specs: Windows XP, 512MB
Hi, I am a Batch newbie and I got some problems with editing a text-based file(vminame.tmp).
The following is an output by "dir"
("..." means shortened)
Line 1| Volume...
Line 2| Volume...
Line 3|
Line 4| Directory...
Line 5|
Line 6|vmware-workstation-full-7.0.0-203739.7z
Line 7| 1 File(s) 518,103,971 bytes
Line 8| 0 Dir(s) 12,219,142,144 bytes free

Note: there is no space before vmware-workstation-full-7.0.0-203739.7z(Line 6)

And I hope the text file would be like this
then(after editing)
Line 1|full-7.0.0-203739.7z

(No "vmware-workstation-")
The text may change,
just get the *.*.

Any ideas?

See More: Edit Text of a Text-based File by Using Batch

Report •

January 15, 2010 at 20:32:17
lots of ways and means... here's one (output in file: mm.u)

@echo off & setlocal enabledelayedexpansion
for /f "tokens=1* delims=:" %%a in ('findstr /L /B "vmware-workstation-" vminame.tmp') do (
set xx=%%b
set xx=!xx:vmware-workstation-=!
>mm.u echo !xx!

Report •

January 15, 2010 at 21:29:01
Thanks nbrane, but the output text doesn't seem to be right:
Volume in drive I has no label.
Volume Serial Number is 44F8-F5CB

Directory of I:\

1 File(s) 518,103,971 bytes
0 Dir(s) 12,219,142,144 bytes free

The single-line text should like this

Report •

January 15, 2010 at 23:03:50
apologies, tez: i looked it over, can't find the problem tonight. I'll resume autopsy tomorrow pending other contributer's inputs/fixes. I'm sure someone will beat me to the punch. it seemed to work over here on limited sample. I feel it must be something very elemental for such a wide divergence of outcomes an i will "smack the hand to forhead" tomorrow!
I'll keep track...

Report •

Related Solutions

January 15, 2010 at 23:50:56
If I just copied your script, it stopped and did nothing...(I test it)
"full-7.0.0-203739.7z"must exist in mm.u.

One more request, can you post a script which can remove "vmware-" in line 6?
Thanks anyway.

Report •

January 16, 2010 at 03:37:28
In response to the opening post:

1. Instead of first creating an output file with too much info, just use the input command (DIR in this case), to restrict to what you want :

dir vmware*.* /b

Or whatever the name of the file(s) are ..

2. For replace purposes ... I've been using a Windows ported sed.exe for years, it's so much easier ... Yes, it's not standard Windows, but it works:

C:\>echo test 123 test test | sed "s/123/got ya/g"
test got ya test test


In a lot of cases its usage to remove strings, is very handy.

Report •

January 16, 2010 at 12:14:15
oh, i see (i think), you had echo enabled... hence all the assorted outputs.
"If I just copied your script, it stopped and did nothing...(I test it)
"full-7.0.0-203739.7z"must exist in mm.u."

did you mean that file mm.u DID contain the line as requested, or not?
if so, to get your second request, change line to:
set xx=%%b
set xx=!xx:vmware-=!

Report •

January 16, 2010 at 22:09:16
to nbrane
That only works when there are spaces in between, but mine's -. So your script output is vmware-, instead of full-7.0.0-203739.7z.

Report •

January 17, 2010 at 01:56:45
Maybe this works
@echo off
dir vmware-workstation*.* > vminame.tmp
for /f "eol= skip=5 delims==" %%N in (vminame.tmp) do (set filename=%%N)
echo %filename%
set filename1=%filename%
set filename1=%filename1:~+19%
echo.%filename1% > mm.u
thanks for everyone's advices here.

Report •

January 17, 2010 at 10:54:55
yours should work, not sure where my wires got crossed, unless you forgot to put the setlocal as:
setlocal enabledelayedexpansion

but that water's passed under the bridge, glad you got yours working, sorry i could not help more.

Report •

Ask Question