We help IT Professionals succeed at work.
Get Started

Change String with Windows Batch  Script

jskfan asked
Last Modified: 2019-12-28
Change String with Windows Batch  Script

I have a CSV file that has computer names, usernames

computername, Newusername 
comp1,  John
CompX, Alton

Open in new window

in each computer C: drive there is a text file (C:\test.txt) that has  a line like this :
aaaaaaaa                  bbbbbbbbbbb        ccccccccccc   -username    username

Open in new window

I want the second username string to be replaced by a string read from the CSV file under usernames ... Note the first username has a dash in front of it and it should stay as it is -username, I need just the second username to be changed.

for instance:
 on comp1 , the line will be
aaaaaaaa                  bbbbbbbbbbb        ccccccccccc   -username    John

Open in new window

 on compX , the line will be
aaaaaaaa                  bbbbbbbbbbb        ccccccccccc   -username    Alton

Open in new window

Thank you
Watch Question
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
This problem has been solved!
Unlock 2 Answers and 13 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE