Samir, You seem to be using XP as XP has a flaw in the output of ipconfig which causes the behaviour you saw (missing trailing quote in the %%f)
You can see here in a hex view of the output using this command
ipconfig >file.txtwhere the characters at the end of the line are not the normal
0D 0A 0D 0A hex are equivalent to 13 10 in decimal, and ascii 13 is a carriage return while ascii 10 is a line feed.
This is Windows XP output:
Code: Select all
0B40:0100 0D 0D 0A 57 69 6E 64 6F-77 73 20 49 50 20 43 6F ...Windows IP Co
0B40:0110 6E 66 69 67 75 72 61 74-69 6F 6E 0D 0D 0A 0D 0D nfiguration.....
0B40:0120 0A 0D 0D 0A 45 74 68 65-72 6E 65 74 20 61 64 61 ....Ethernet ada
0B40:0130 70 74 65 72 20 4C 6F 63-61 6C 20 41 72 65 61 20 pter Local Area
0B40:0140 43 6F 6E 6E 65 63 74 69-6F 6E 20 31 34 3A 0D 0D Connection 14:..
0B40:0150 0A 0D 0D 0A 20 20 20 20-20 20 20 20 43 6F 6E 6E .... Conn
0B40:0160 65 63 74 69 6F 6E 2D 73-70 65 63 69 66 69 63 20 ection-specific
0B40:0170 44 4E 53 20 53 75 66 66-69 78 20 20 2E 20 3A 20 DNS Suffix . :
This is Windows 8 output:
Code: Select all
0B44:0100 0D 0A 57 69 6E 64 6F 77-73 20 49 50 20 43 6F 6E ..Windows IP Con
0B44:0110 66 69 67 75 72 61 74 69-6F 6E 0D 0A 0D 0A 0D 0A figuration......
0B44:0120 45 74 68 65 72 6E 65 74-20 61 64 61 70 74 65 72 Ethernet adapter
0B44:0130 20 4C 6F 63 61 6C 20 41-72 65 61 20 43 6F 6E 6E Local Area Conn
0B44:0140 65 63 74 69 6F 6E 20 32-3A 0D 0A 0D 0A 20 20 20 ection 2:....
0B44:0150 43 6F 6E 6E 65 63 74 69-6F 6E 2D 73 70 65 63 69 Connection-speci
0B44:0160 66 69 63 20 44 4E 53 20-53 75 66 66 69 78 20 20 fic DNS Suffix
0B44:0170 2E 20 3A 20 0D 0A 20 20-20 4C 69 6E 6B 2D 6C 6F . : .. Link-lo
When using XP and ipconfig you see
0D 0D 0A where there are two carriage returns in sequence at the end of each line.
This is fixed in Windows Vista, 7 and 8 but there is a workaround for XP
The second issue you had was explained by compo - when you use a single delimiter of
: then you get the leading space - which I was trying to let you discover, but it was complicated by the above.
Lastly - when using
%%~nA it gives you the
filename part of the string, but an IP address has an "extension" which cmd recognises as the part from the last period in the string. That is why the last octet of the IP address wasn't printed.
You can use
%%~nxA when parsing strings to make sure that it never removes the end of the string by mistake.
I hope that helps to explain some of the odd behaviour that you saw.