jskfan
asked on
Change String with Windows Batch Script
Change String with Windows Batch Script
I have a CSV file that has computer names, usernames
example
in each computer C: drive there is a text file (C:\test.txt) that has a line like this :
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
on compX , the line will be
Thank you
I have a CSV file that has computer names, usernames
example
computername, Newusername
comp1, John
CompX, Alton
....
in each computer C: drive there is a text file (C:\test.txt) that has a line like this :
aaaaaaaa bbbbbbbbbbb ccccccccccc -username username
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
on compX , the line will be
aaaaaaaa bbbbbbbbbbb ccccccccccc -username Alton
Thank you
Do you need to read the c:\test.txt file on multiple remote computers to get the aaaaaaaa string?
ASKER
No ...each computer c:\test.txt has the same string :
I want the second username to be replaced by the Newusername specified in the CSV file.
aaaaaaaa bbbbbbbbbbb ccccccccccc -username username
I want the second username to be replaced by the Newusername specified in the CSV file.
> I want the second username to be replaced by the Newusername specified in the CSV file
Where is this 'second username'? I don't see it in your post
Where is this 'second username'? I don't see it in your post
ASKER
each computer has in its C:\test.txt, a line as follows:
you can see username twice the first one is preceded by a dash "-" that one stays as is. The second username needs to be replaced
aaaaaaaa bbbbbbbbbbb ccccccccccc -username username
you can see username twice the first one is preceded by a dash "-" that one stays as is. The second username needs to be replaced
> you can see username twice the first one is preceded by a dash "-" that one stays as is. The second username needs to be replaced
I don't see it. Is it in the csv or txt file?
I don't see it. Is it in the csv or txt file?
ASKER
in the Text file C:\test.txt
aaaaaaaa bbbbbbbbbbb ccccccccccc -username username
To clarify - there is one parameter (literal string) "-username" and a uersname (which is different on each PC). The non-literal username needs to be replaced.
I cannot see it on mobile: Is the CSV file tab delimited?
Everything but the username stays the same? Because it is much more simple to just write a string to remote than to replace a value.
I cannot see it on mobile: Is the CSV file tab delimited?
Everything but the username stays the same? Because it is much more simple to just write a string to remote than to replace a value.
ASKER
CSV is comma delimited ..
computername, Newusername
comp1, John
CompX, Alton
Everything but the username stays the same?: Yes
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Qlemo,
Sorry you can name it whatever name you want. the CSV will be like this:
I do not think you need csv and txt files at the same time
CSV already has computer name that the script will access and the username that will be changed.
example : the script will access Comp1 and changethe second "username" string to John ..
Sorry you can name it whatever name you want. the CSV will be like this:
computername, Newusername
comp1, John
CompX, Alton
....
I do not think you need csv and txt files at the same time
CSV already has computer name that the script will access and the username that will be changed.
example : the script will access Comp1 and changethe second "username" string to John ..
aaaaaaaa bbbbbbbbbbb ccccccccccc -username username
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I just tried it, the script opens up the CSV file, it does not replace the username on the targeted computers.
ASKER
I will see if I can get it to work later.
Thank you
Thank you