Trying to use new line as delimiter in FOR /F (kind of..)

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Trying to use new line as delimiter in FOR /F (kind of..)

Post by MigrationUser »

21 Dec 2012 20:56
npocmaka

Basically FOR /F cannot use a new line as delimiter
- it can be worked around with counting lines and etc. ,but here's something else that I want to try.But it does not work and I don't know why:

Code: Select all

@echo off
for /f "delims=¦ tokens=1,2" %%O in ('
	@echo off ^&
	for  /f "usebackq tokens=*" %%I in ^(^`
		ipconfig
	^`^) do ^(
		^<nul set /p ".=¦%%I"
	^)
') do (
	echo %%O
)
According to my theory this should print the first two lines . ( In case it's not so obvious - I'm calling FOR /F as command in FOR /F and printing the exit form the command in inner FOR /F in one line plus "¦" which will be used as delimiter in outer FOR /F .The delimiter should be just a symbol that has a little chances to be contained in command out put .I've tried also with a normal ascii character - but again the same. )
If I use * in tokens parameter it works.
I've wondered if there's not visible LF or CR symbol that was not escaped ,but I've checked the produced string with a HEX editor and didn't saw such thing.

:-) . Any ideas?

----------------------------

#2 22 Dec 2012 02:28
dbenham


Don't groan too loadly....

Each line becomes a token, but you forgot to print out the 2nd token ;)

Code: Select all

@echo off
for /f "delims=¦ tokens=1,2" %%O in ('
	@echo off ^&
	for  /f "usebackq tokens=*" %%I in ^(^`
		ipconfig
	^`^) do ^(
		^<nul set /p ".=¦%%I"
	^)
') do (
	echo %%O
        echo %%P
)
Dave Benham

----------------------------

#3 22 Dec 2012 10:38
npocmaka


Aghh... I'm such an idiot.
Post Reply