Good ol for do loop

Home Forums Scripting DOS Command Shell Good ol for do loop

This topic contains 3 replies, has 4 voices, and was last updated by Avatar MR_Aguilera 5 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatar
    meksiki
    Member
    #164353

    Hi folks!

    So basically I have a .txt file that contains 2 lines. I want to take line 2 of the file and set it as a variable

    I’m typing this in the command prompt to test it out the code, but it’s not printing anything out

    For /f “skip=1 %G IN (“file.txt”) do @echo %G
    [/CODE] To implement this in my batch file I tried this, but it’s a no go

    [CODE]
    FOR /f “skip=1” %%G IN (“textfile.txt”) do (
    %%G=%variable%
    echo %variable%
    )
    [/CODE]
    it’s not printing anything. My prompt is in the same folder s the file (c:users[I]user[/I]) I’m sure my code is missing something, but not really sure what. If you somebody could point me in the right direction I’d greatly appreciate it

    Edit:
    Line 2 of the text file has no spaces, it’s actually the SID of a user profile[CODE]
    For /f “skip=1 %G IN (“file.txt”) do @echo %G
    [/CODE] To implement this in my batch file I tried this, but it’s a no go

    FOR /f “skip=1” %%G IN (“textfile.txt”) do (
    %%G=%variable%
    echo %variable%
    )
    [/CODE]
    it’s not printing anything. My prompt is in the same folder s the file (c:users[I]user[/I]) I’m sure my code is missing something, but not really sure what. If you somebody could point me in the right direction I’d greatly appreciate it

    Edit:
    Line 2 of the text file has no spaces, it’s actually the SID of a user profile[CODE]
    FOR /f “skip=1” %%G IN (“textfile.txt”) do (
    %%G=%variable%
    echo %variable%
    )
    [/CODE]
    it’s not printing anything. My prompt is in the same folder s the file (c:usersuser) I’m sure my code is missing something, but not really sure what. If you somebody could point me in the right direction I’d greatly appreciate it

    Edit:
    Line 2 of the text file has no spaces, it’s actually the SID of a user profile

    Avatar
    MR_Aguilera
    Member
    #390377

    Re: Good ol for do loop

    is this what you’re trying to do:

    Bzg4gD9IEAE36Uq.png

    of course, you would have to replace %g with %%g if used in a script.

    -Ricc

    Rems
    Rems
    Moderator
    #228452

    Re: Good ol for do loop

    Add UseBackQ to the For options, because there are double quotes around the file name.

    “usebackq skip=1”

    /Rems

    Avatar
    barrboy
    Member
    #390370

    Re: Good ol for do loop

    Thank you guys for your replies!

    I actually found a better way to implement what I was trying to do. I work on a helpdesk and rebuilding profiles can take a lot of time. I decided to make a batch file to speed this process up. It took a lot of learning but after a week I was able to get working, and working safely at that. Right now I’m just fixing some things and adding some functionality then eventually I’ll pass it on to my colleagues.

    Normally on a call rebuilding a Windows profile can take up to 10 minutes when using the registry editor. My batch file can do it under a minute. It was such a great feeling when I finally got it working.

    I plan on leaning how to use Visual Studio and making an application that does the same thing as the batch file

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.