Page 1 of 1

[SOLVED]Like TYPE command, but when it appears in the pro...

Posted: 18 Jan 2011 11:01
by akol
Here I am again, sory. :roll:

Like TYPE command, but when it appears in the prompt enumerates.

For example:

My file.txt is this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum feugiat commodo magna aliquis nulla in ultrices ac.
Vulputate velit level kiosk erat feugiat molestie.

And when it is printed at the prompt (like "type file.txt") to appear this way:
1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
2. Vestibulum feugiat commodo magna aliquis nulla in ultrices ac.
3. Vulputate velit level kiosk erat feugiat molestie.

That is, the file file.txt is unchanged. Only the prompt will appear enumerated.
Is there any parameter of the TYPE command or a function that makes this possible? :oops:

Re: [HELP]Like TYPE command, but when it appears in the prom

Posted: 18 Jan 2011 12:52
by aGerman
FINDSTR /N could help.
Try:
findstr /n "^" file.txt
or for unicode text:
type file.txt|findstr /n "^"

But the line number is separated by a colon.
To make it look like you want try this function:

Code: Select all

@echo off &setlocal
call :enumerate "file.txt"
pause
goto :eof

:enumerate FileName
for /f "tokens=* delims=1234567890" %%a in ('type "%~1"^|findstr /n "^"') do (
  set "line=%%a"
  set /a n+=1
  setlocal enabledelayedexpansion
  echo(!n!. !line:~1!
  endlocal
)
goto :eof

Regards
aGerman

Re: [HELP]Like TYPE command, but when it appears in the prom

Posted: 18 Jan 2011 15:39
by akol
aGerman, thanks for fast reply, the first way is great.
Exelent forum! Congratulations!

Re: [SOLVED]Like TYPE command, but when it appears in the pr

Posted: 13 Feb 2011 23:07
by Raffy73
Hi aGerman. The solution you posted is the direct solution to my problem. You are really really very good on this matters. I have the same issue with akol and I'm glad I found this forum. I'm so thankful that my long time problem is now solved. Thank you. You are a blessing to us.