Remove weird rectangle at end of line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Andytan91
Posts: 1
Joined: 04 Aug 2010 22:06

Remove weird rectangle at end of line

#1 Post by Andytan91 » 15 Aug 2010 08:29

Hello guys i ran the code to remove spaces for the ipconfig command and i met this problem whereby theres an invisible rectangle after .134..i am wondering how to solve this..thanks in advance:)


Result:
IPAddress............:192.168.199.134[]-< weird rectangle


Code:
SETLOCAL EnableDelayedExpansion
IPCONFIG | findstr /C:"IP Address" >> IPCONFIG.txt


for /f "delims=" %%a in (IPCONFIG.txt) do (
set line=%%a
set line=!line: =!
!
echo !line! >> IPCONFIGNS.txt
)

FOR /f "tokens=2 delims=:" %%a IN (IPCONFIGNS.txt) DO (
SET IP=%%a
)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Remove weird rectangle at end of line

#2 Post by aGerman » 15 Aug 2010 09:13

Normally a line ends with 0D 0A (Carriage Return + Line Feed).
The bug of IPCONFIG is that the lines end with 0D 0D 0A. So you have one unintended CR character (some editors show it as rectangle).
If you loop over the output you can normalize it by %%~nxa instead of %%a.

Much shorter and without additional files:

Code: Select all

setlocal EnableDelayedExpansion
for /f "delims=: tokens=2" %%a in ('ipconfig^|findstr /c:"IP"') do (set "IP=%%~nxa" &set "IP=!IP: =!")


Regards
aGerman

Post Reply