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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
akol
Posts: 7
Joined: 18 Jan 2011 04:47

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

#1 Post by akol » 18 Jan 2011 11:01

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:
Last edited by akol on 18 Jan 2011 15:41, edited 1 time in total.

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

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

#2 Post by aGerman » 18 Jan 2011 12:52

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

akol
Posts: 7
Joined: 18 Jan 2011 04:47

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

#3 Post by akol » 18 Jan 2011 15:39

aGerman, thanks for fast reply, the first way is great.
Exelent forum! Congratulations!

Raffy73

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

#4 Post by Raffy73 » 13 Feb 2011 23:07

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.

Post Reply