0

The task is to iterate through each line in a file named alts.txt. Then I grab the line and split it at the semicolon and print out the text before the semicolon and after the semicolon.

My file looks something like this...

username:password
username2:password2
username3:

My current code is this:

setlocal ENABLEDELAYEDEXPANSION
set file=alts.txt
for /f "tokens=*" %%A in (%file%) do (
    set str=%%A
    set "username=%str::="^&REM #%
    set "pass=%str:*:=%"
    echo username=%username% pass=%pass%
)
pause

If someone would be kind enough to show me my error and EXACTLY how to fix the error it would be greatly appreciated.

2
  • Just to be clear, is this with cmd.exe? Commented Apr 29, 2014 at 1:33
  • @ClickRick it is a .bat file Commented Apr 29, 2014 at 1:36

1 Answer 1

2
@echo off
setlocal ENABLEDELAYEDEXPANSION
set file=alts.txt
for /f "tokens=1,2 delims=:" %%A in (%file%) do (
    set "$user=%%A"
    set "$pass=%%B"
    echo username=!$user! pass=!$pass!
)
pause

Be careful using %username%. It's a system variable. You can test writing echo %username% in the CMD prompt. You better choose another name for the Variable like i did.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.