0

Can anyone show me a example of a bat file that copies the first and second line from a txt file..

I need way to have 2 bat files. One copies the first line to clipboard, and a second bat file to copy the second line.

So if I have a txt file that contains:

username
password

I want one bat file to copy the username and the second bat the password..

Could some give me an example of how to do this?

Xenosis
  • 87
  • 1
  • 7

1 Answers1

0

copy first line to clipboard:

<file.txt set /p usr=
echo %usr%|clip

copy second line:

<file.txt (
  set /p pwd=
  set /p pwd=
)

(where the first set /p pwd= is reading the first line and the second one overwrites the variable with the second line)

or use one batchfile for both and put two lines to clipboard (might or might not work with your application; try it out):

<file.txt (
  set /p usr=
  set /p pwd=
)
(
  echo %usr%
  echo %pwd%
)|clip

this is probably easier with just:

clip < file.txt

which copies the whole file content to the clipboard.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • before you ask: there is no utility in Windows to *get* the contents of the clipboard (although there are some third-party solutions you can download from the internet) – Stephan Mar 01 '18 at 11:39
  • I don't know, what exactly you want to do, maybe [this](https://stackoverflow.com/a/43118510/2152082) could work for you. – Stephan Mar 01 '18 at 11:59
  • I'm using jitbit macro recorder to navigate and paste the login into the program.. If I make bat file with: – Xenosis Mar 01 '18 at 12:08
  • did you `echo off` before? – Stephan Mar 01 '18 at 12:11
  • I'm very noob with batch files, so I'm unsure what you mean sorry.. But I just found another script i think i can use: @echo off for /f %%G IN (login.txt) DO if not defined line set "line=%%G" echo %line%| clip Adding clip to the script above looks to be working and if I need the second line I add "skip=1" – Xenosis Mar 01 '18 at 12:33