0

Environment Windows 10,
C:\Folder_With_VMXfiles, installed sed for windows

Tools: Batch script, sed for Windows

Requirements:

In folder C:\Folder_With_VMXfiles Need to replace some text inside the vmx files with another. But the replacing text is specific to every .vmx file.

Example:

  • VMX file 1 has string "COM2" inside and want to replace it with "COM33"
  • VMX file 2 has string "COM3" inside and want to replace with "COM34"

I tried to do with nested for loops but i could get the desired results. Basically i need to loop through the directory , select the ".vmx" files and use sed to replace text.

Tried:

@echo off

for /f %%i in ("Folder_With_VMXfiles") do ( 
    echo %%i
    for /l %%j in (1,1,9) do (
         sed -i "s/COM/COM%%j/" %%i )

 ) 
Sven
  • 98,649
  • 14
  • 180
  • 226

1 Answers1

0

You don't tell anything about the naming of the vmx files?
1.vmx, 2.vmx?
And why do you need a for when you know the names?

@Echo off
Pushd "X:\Folder\with\vmxfiles"
sed -i "s/COM2/COM33/" 1.vmx
sed -i "s/COM3/COM34/" 2.vmx
Popd

A dynamic approach assigning a COM port of two greater than the Clone number

@echo off
Pushd "Folder_With_VMXfiles"

for /l %%j in (2,1,9) do Call :sub %%j
Goto :Eof

:Sub
Echo Prcessing Clone%1.vmx
Set /A NewCom=%1 +2
Echo sed -i "s/COM\d+/COM%NewCom/" Clone%1.vmx

I don't know the maximal assignable com port number. To have sed actually change values remove the echo in the last line.

LotPings
  • 1,015
  • 7
  • 12