Solved Need help in accomplishing the code to echo the tokens

March 6, 2020 at 05:08:10
Specs: Windows 10, 4GB RAM
Like in this code below after the search of the tokens , i want to echo it the tokens found?
Note: tokens are several and i wanted all of them echoed

@echo off
cls
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in ('type profiles.txt ^| find ":"') do (

::what code should be written here ??
)


See More: Need help in accomplishing the code to echo the tokens


✔ Best Answer
March 9, 2020 at 17:32:52
re post #6: it should work without those exclaims since it's a "system" variable.
As for the problem, this worked for me:
for /f "tokens=2 delims=:" %%a in (profiles.txt) do @echo %%a

If there are other instances of the colon that have content following the colon, you may need the 'find', otherwise this worked ok in my test on your sample. There is, however,
one space before each name due to the delims-colon requirement. To get rid of that space, you'll need a two-liner:
@echo off
for /f "tokens=2 delims=:" %%a in (profiles.txt) do for /f "tokens=1*" %%b in ("%%a") do echo %%b %%c

message edited by nbrane



#1
March 6, 2020 at 08:43:00
@echo off&cls&setlocal enabledelayedexpansion
for /f "tokens=*" %%1 in ('type profiles.txt ^| find ":"') do (
echo %%1
)

specs: https://www.userbenchmark.com/UserR...


Report •

#2
March 6, 2020 at 09:11:48
i have already tried that but it only give me one result, which is at the end of the txt file. I want something that will give all the tokens rather than one. i was thinking of using an array but it didn't display any result back, may be it is my syntax or something else am not sure

Report •

#3
March 6, 2020 at 17:53:32
I, for one, need a "for example" sample of your input (profiles.txt) and what you want the output to look like. I can't get a clear picture from your descriptions so far.

Report •

Related Solutions

#4
March 8, 2020 at 23:55:45
@nbrane Let me put it this way. I have an output of my of my wi-fi profiles in a txt files like so, saved in a text file name profiles.txt

`````````````
Profiles on interface Wi-Fi:

Group policy profiles (read only)
---------------------------------
<None>

User profiles
-------------
All User Profile : Test
All User Profile : Test1
All User Profile : Test 2
All User Profile : Example
All User Profile : Example 1
All User Profile : Wifi

`````````
How do i filter it to only remain with the names only like so,
`````````
Test
Test1
Example
Example 1
Wifi


Report •

#5
March 9, 2020 at 03:01:13
guy i have managed to do it .. This worked for me
```````
@echo off
cls
color a
setlocal enabledelayedexpansion
findstr /v /i /c:"Profiles on interface Wi-Fi:" profiles.txt >newprofiles.txt


pause
```````````````

followed by this batch script
`````````````
@echo off
cls
color a
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('type newprofiles.txt ^| find ":"') do (

echo !%%a!
)
pause

````````````````````````````

message edited by RomGeek


Report •

#6
March 9, 2020 at 03:20:35
@hidde663 without the exclamation marks enclosing echo like so -> echo !%%a! it won't work

Report •

#7
March 9, 2020 at 17:32:52
✔ Best Answer
re post #6: it should work without those exclaims since it's a "system" variable.
As for the problem, this worked for me:
for /f "tokens=2 delims=:" %%a in (profiles.txt) do @echo %%a

If there are other instances of the colon that have content following the colon, you may need the 'find', otherwise this worked ok in my test on your sample. There is, however,
one space before each name due to the delims-colon requirement. To get rid of that space, you'll need a two-liner:
@echo off
for /f "tokens=2 delims=:" %%a in (profiles.txt) do for /f "tokens=1*" %%b in ("%%a") do echo %%b %%c

message edited by nbrane


Report •

#8
March 9, 2020 at 22:13:37
Thanks @nbrane it work perfectly

Report •

#9
March 10, 2020 at 04:46:14
and how do i assign process to the output, for example;

I echoed the result in a text file, call it res.txt how then can i loop through file and creating users accounts with the results in the text file

message edited by RomGeek


Report •

#10
March 10, 2020 at 05:03:14
I have managed to solve for creating accounts don't mind it

Report •

#11
March 10, 2020 at 05:12:00
too late ^^

i have no clue what is written in res.txt, i assume firstname<space>lastname
ChangeThis1 represents the password
pretty sure you need to run the .bat as admin to be able to create users


@echo off
::the below line writes 0 bytes to res.txt
echo off>res.txt
for /f "tokens=2 delims=:" %%a in (profiles.txt) do (
for /f "tokens=1*" %%b in ("%%a") do (
echo %%b %%c >>res.txt
)
)
echo Create users written in res.txt?
echo [1] Yes
echo [2] No
choice /c 12 /n>nul
if %errorlevel%==2 exit/b
for /f "tokens=1,2 delims= " %%a in ('type "res.txt"') do (
net user %%a_%%b ChangeThis1
)

specs: https://www.userbenchmark.com/UserR...


Report •

#12
March 10, 2020 at 05:12:26
glad to hear you've fixed it tho :)

specs: https://www.userbenchmark.com/UserR...


Report •

Ask Question