-1

I apologize for the vagueness of my question.

I wanted to be able to take information and stack it in a file, the pull the information from the file in line.

The way that I am able to do this at this time is with:

:: simple setting of variables
Set var1=var..
Set var2=var..
Set var3=var..
Set fullvar=%var1%%var2%%var3%
:: now push to file
Echo fullvar > file

Before I asked my question I did not realize I could stack my variables in this way.

I am going back through batch tutorials.

Can this question be closed?

Thank you for you assistance.

Original transcript below

I am looking for a way to put my variables into a file in line. With >> I can append a new line, I want to have my var% in line...

Ex:

Type file2

returns %var1% %var2% %var3%

Instead of;

%var1%
%var2%
%var3%

:eof

I want to be able to use them as %1 %2 %3 in my batch program.

Here is the basic information I am using.

Echo off
cls
ping /n 1 ipaddress1Var > file
ping /n 1 ipaddress2Var >> file
findstr /i "ttl=" file > file2
Type file2
pause
:eof

this returns the line included with ttl= to the new file. I am not sure how to write what I want this to do;

When I > or >> to file2 I want to add to the line that it is written to instead of a new line.

Unfortunatly I do not have my computer I wrote the batch file on with me. I want to expand the capabilities of the script.

I am learning more intermediate batch programming on a WinXP laptop.

Any help or pointing in the right direction would help. This does not google well.

Cheers

Maybe

Echo %var1% %var2% %var3% > file# 

Would work for building the file in line. I am just not sure how to read and re-assign the variables properly....

1 Answers1

0

Is this what you are after?

MyFile.bat

for /F "tokens=*" %%a in ('ping /n 1 cnn.com    ^| findstr TTL') do (set TTL_1=%%a)
for /F "tokens=*" %%a in ('ping /n 1 google.com ^| findstr TTL') do (set TTL_2=%%a)
echo %TTL_1% %TTL_2% > OUTPUT.txt

After this, the file OUTPUT.txt contains:

Reply from 151.101.128.73: bytes=32 time=25ms TTL=56 Reply from 216.58.194.142: bytes=32 time=18ms TTL=54

(two entries, back-to-back, on one line)

abelenky
  • 63,815
  • 23
  • 109
  • 159