Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Adding characters to variable in FOR loop
Name: keridbey Date: July 17, 2009 at 12:08:28 Pacific OS: Windows XP CPU/Ram: 1.3 Ghz / 1 Gb RAM Subcategory: Batch
Comment:
We have a batch file that outputs MAC addresses without any colons or dashes. I'm trying to write a small script that will simply add dashes for every third character in the string. I was attempting to do it in a FOR /F loop, but couldn't get the individual characters in %%a separated.
An example of a MAC address we have would be: "0024e8919447" I would want to make it "00-24-e8-91-94-47" I have text files with ten to twenty MAC addresses each like this.
I've done this with variables in the past, just never within a FOR /F loop. Is there a simpler way to do this?
Name: Mechanix2Go Date: July 17, 2009 at 13:16:36 Pacific
Reply:
@echo off > newfile & setLocal enableDELAYedexpansion
for /f "tokens=* delims= " %%a in (MAClist) do ( set s=%%a echo !s:~0,2!-!s:~2,2!-!s:~4,2!-!s:~6,2!-!s:~8,2!-!s:~10,2!>> newfile )
===================================== If at first you don't succeed, you're about average.
M2
0
Response Number 2
Name: ghostdog Date: July 17, 2009 at 17:17:27 Pacific
Reply:
here's a vbscript
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strMAC = objArgs(0)
For i=1 To Len(strMAC) Step 2
s=s & Mid(strMac,i,2)&"-"
Next
WScript.Echo Left(s,Len(s)-1)
Name: keridbey Date: July 20, 2009 at 06:46:59 Pacific
Reply:
Mechanix2Go: As usual, your script worked like a charm! Thanks!!!
ghostdog: I'm keeping as much of my stuff in batch for the time being, but I appreciate the VBS as well! I will definitely hang on to that for future use!! Thanks!
Summary: I want to count in for loop but did not work. here is my code. set count= for /f "tokens=*" %%s in (external_ip.dat) do ( set /a COUNT+=1 echo %count% java -cp %JCP% %APP_NAME_EXT_IP%...
Summary: I'm using a for loop and the main variable is %%x which the name of an ac3 file. I'm transcoding that to an mp4 file. I would like to be able to get the first character from the name of file being pro...
Summary: I have this little script which has a settings file so the batch doesn't have to be edited. echo Drag and drop settings file onto this window then hit enter set /p settings= for /f "tokens=*" %%a in (...