Jump to content

I would really appreciate some help

PUGZSZ

I am extremely new to coding in general, I am trying to find out how to write a program that can read a .txt file and then rearrange a name in the text file and insert that name inside of a cmd command back into that file and save it. For example if the text file says John Doe then it would change to DoeJ and be inserted into a psshutdown command like "psshutdown \\doej -f". I have no idea where to start and i would really appreciate the help.

Link to comment
Share on other sites

Link to post
Share on other sites

Not sure about the nature of the system you're on, but I found Python to be particularly good at parsing files and doing system commands. 
I used Python to go through any number of XML files and rename them according to their respective name tags in those files--not the same thing of course, but it did involve using system commands based on the contents of a file.  

 

If you're on a Linux/Unix system, you maybe able to use BASH scripts to do the same, but I'm not familiar enough on that to help you there.

-trust your technolust

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, void_presence said:

Not sure about the nature of the system you're on, but I found Python to be particularly good at parsing files and doing system commands. 
I used Python to go through any number of XML files and rename them according to their respective name tags in those files--not the same thing of course, but it did involve using system commands based on the contents of a file.  

 

If you're on a Linux/Unix system, you maybe able to use BASH scripts to do the same, but I'm not familiar enough on that to help you there.

I'm on a windows machine

Link to comment
Share on other sites

Link to post
Share on other sites

Python's still applicable.  The program I mentioned previously I wrote and used on a Windows machine

-trust your technolust

Link to comment
Share on other sites

Link to post
Share on other sites

39 minutes ago, PUGZSZ said:

I am extremely new to coding in general, I am trying to find out how to write a program that can read a .txt file and then rearrange a name in the text file and insert that name inside of a cmd command back into that file and save it. For example if the text file says John Doe then it would change to DoeJ and be inserted into a psshutdown command like "psshutdown \\doej -f". I have no idea where to start and i would really appreciate the help.

I see that the answers are going to be all over the place. 

We need more information from you, what language have you been learning?

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, straight_stewie said:

I see that the answers are going to be all over the place. 

We need more information from you, what language have you been learning?

I dont know much of anything, i've been trying to learn what i can

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, PUGZSZ said:

dont know much of anything, i've been trying to learn what i can

So have you picked a language at all? Is this your first project? 

In any case, what else are your long term goals for programming?

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

It is my first program, i want to learn python in the short term. Long term i dont really know

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, straight_stewie said:

So have you picked a language at all? Is this your first project? 

In any case, what else are your long term goals for programming?

Ive been looking into python and i have started to practice some but i cannot get a text file to be read and set as a string

 

Link to comment
Share on other sites

Link to post
Share on other sites

CMD on windows is atrocious. Seriously, don’t develop on windows unless you obviously have to.

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, PUGZSZ said:

I am extremely new to coding in general, I am trying to find out how to write a program that can read a .txt file and then rearrange a name in the text file and insert that name inside of a cmd command back into that file and save it. For example if the text file says John Doe then it would change to DoeJ and be inserted into a psshutdown command like "psshutdown \\doej -f". I have no idea where to start and i would really appreciate the help.

So, something like this batch file?

@echo off
Setlocal EnableDelayedExpansion
title Just a screwing yo mom....
for /F "tokens=*" %%A in (users.txt) do (
    for /F "tokens=1,2 delims=. " %%y in ("%%A") do (
        set userid=%%y
        set firstchar=!userid:~0,1!
        REM echo %%y %%z - !firstchar!
        set user=%%z!firstchar!
        echo Sending shutdown to \\!user!
        psshutdown \\!user! -f
        echo Shutdown sent to \\!user!
    )
)
pause

Just pop that into a notepad document and save it with the file extension as .bat

 

 

 

This is the contents of the users.txt file

john doe
Mary Poppins
Jack Black

Does the trick.

 

Regards,

Leon.

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, PUGZSZ said:

Ive been looking into python and i have started to practice some but i cannot get a text file to be read and set as a string

If you're goal is to learn how to program, then don't fall into the trap of making copy pasta out of results posted around. You will never learn anything other than how to be a non malicious "script kitty".

Are you using python 2.7 or 3.6? If you are unsure, you can find out by writing a program that imports the "sys" module, and then prints the result of the command "sys.version".

One of the best skills you can learn in programming is how to read documentation. Professional developers spend vastly more time reading documentation and communicating with other developers than they do actually writing code.

 

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×