Solved How to stop a SPACE from importing as part of a variable?

July 20, 2014 at 20:39:28
Specs: Windows 7
I have a script that exports the first 3 octets of an IP address to a file (IP.txt). When it exports, it is adding a space at the end of the line, as well as a new line. When the test is imported from the file, the space is included. The issue that I have with this is that the length of the IP is not static. I am needing a way to remove the space at the end of the line, or to prevent it from being the txt file without manually modifying it.

I am writing the info to file via:
:SET_IP
SET OCT2=
SET OCT3=
SET /p OCT2=Please enter IP Octet 2:
SET /p OCT3=Please enter IP Octet 3:
SET IP_BASE=10.%OCT2%.%OCT3%.
ECHO %IP_BASE% > IP.txt

I am importing the text back at a script opening via:
IF EXIST IP.txt (
SET /p IP=<"IP.txt"
) ELSE (
GOTO SET_IP
)


Say that I set OCT2 as 22 and OCT3 as 33, this SHOULD output as "10.22.33."
It is, however outputting as "10.11.22.
"

When calling this info into a batch script, it then comes back as "10.22.33. "

Is there a way that I can script the removal of the last character (the " ") or to prevent it from being written in the first place?


See More: How to stop a SPACE from importing as part of a variable?

Report •

#1
July 20, 2014 at 21:14:27
✔ Best Answer
:SET_IP
SET OCT2=
SET OCT3=
SET /p OCT2=Please enter IP Octet 2:
SET /p OCT3=Please enter IP Octet 3:
SET IP_BASE=10.%OCT2%.%OCT3%.
> IP.txt ECHO %IP_BASE%

=====================
M2 Golden-Triangle


Report •
Related Solutions


Ask Question