0

I'm trying to translate input formatted like this: abcd12-34defg and translate it to this: ab-cd-12-34-de-fg

My code:

@echo off
:start
set /p macid="please enter mac id:" 
echo %macid%
goto start

Current output:

please enter mac id: abcd12-34defg    
abcd12-34defg

Goal:

please enter mac id: abcd12-34defg    
ab-cd-12-34-de-fg
Matthew
  • 6,351
  • 8
  • 40
  • 53
deschus
  • 25
  • 3

1 Answers1

0

Well, if that's the fixed entry format, this will work:

@echo off
setlocal EnableDelayedExpansion

set /p macID="please enter mac id:" 

call :print_token 0 2 -
call :print_token 2 2 -
call :print_token 4 2 -
call :print_token 7 2 -
call :print_token 9 2 -
call :print_token 11 2 

goto :eof

:print_token
echo | set /p dummyVar=!macID:~%1,%2!%3
exit /b 0

Regarding the echo | set /p dummyVar=, it is used to echo values without line breaks. Take a look at this for further information.

If you expect a non-fixed input format, then you need to clean up extrange characters first, and then split like shown in this example. After cleaning the input value, you could easily turn the call :print_token sequence into a for loop, for improved clarity.

Sample run:

please enter mac id:abcd12-34defg
ab-cd-12-34-de-fg
Community
  • 1
  • 1
carlossierra
  • 4,479
  • 4
  • 19
  • 30
  • that working fine.... now if i want to use %macID% for further commands ... how to use the new generated output ? – deschus Aug 31 '16 at 07:38
  • @deschus I'm glad it is working correctly. Regarding your new request, you need to open a new question with the specifics of the usage you intend to make. If you found this useful, please remember to upvote and mark as accepted! – carlossierra Aug 31 '16 at 12:10