Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to number lines in text file

12 views
Skip to first unread message

µ

unread,
Aug 23, 2006, 5:22:23 AM8/23/06
to
I see that some people put numbers in square brackets in front of
their batch lines. (Like Bilious does in his posts)
How can I do this?

So in front of every line there should be [1] [2] and so on.


Thanks

billious

unread,
Aug 23, 2006, 7:26:05 AM8/23/06
to

"ľ" <m...@nospam.skepp.be> wrote in message
news:je7oe2dkg30envcai...@4ax.com...

[1]@echo off&setlocal
[2]set yfn=%1
[3]if not defined yfn echo Syntax : textify filename&echo (textifies
filename.bat to filename.txt)&goto :eof
[4]if not exist %yfn%.bat echo %yfn%.bat not found&goto :eof
[5]if not exist %yfn%.txt goto run
[6]set yyn=
[7]:ask
[8]set /p yyn=%yfn%.txt exists - overwrite
[9]if not defined yyn goto ask
[10]if /i %yyn%==Y goto run
[11]echo processing cancelled&goto :eof
[12]:run
[13]find /v /n "" <%yfn%.bat >%yfn%.txt
[14]dir %yfn%*

The secret is in line [13] The rest of the batch is for convenience.


Matt Williamson

unread,
Aug 23, 2006, 9:25:58 AM8/23/06
to
Billious's code only works if your files have a .bat extension. I've
modified it so it will work with any file extension because I used .cmd and
it didn't work when I first tried it. I also prefer to just drag and drop
and have the new code pop up, so I added that too.

[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]cd /d %~dp0
[4]for %%a in ("%1") do set ext=%%~xa
[5]for %%a in ("%1") do set file=%%~na
[6]set yfn=%file%
[7]if not defined yfn echo Syntax : textify filename&echo (textifies
filename%ext% to filename.txt)%goto :eof
[8]if not exist %yfn%%ext% echo %yfn% not found&goto :eof
[9]if not exist %temp%\%yfn%.txt goto run
[10]set yyn=
[11]:ask
[12]set /p yyn=%yfn%.txt exists - overwrite
[13]if not defined yyn goto ask
[14]if /i %yyn%==Y goto run
[15]echo processing cancelled&goto :eof
[16]:run
[17]find /v /n "" <%yfn%%ext% >%temp%\%yfn%.txt
[18]notepad "%temp%\%yfn%.txt"
[19]del %temp%\%yfn%.txt

HTH

Matt

--
Posted via a free Usenet account from http://www.teranews.com

µ

unread,
Aug 23, 2006, 5:56:58 PM8/23/06
to
Needless to say that you both are great!
Thanks

Dr John Stockton

unread,
Aug 23, 2006, 4:04:08 PM8/23/06
to
JRS: In article <je7oe2dkg30envcai...@4ax.com>, dated
Wed, 23 Aug 2006 11:22:23 remote, seen in news:alt.msdos.batch.nt, µ
<m...@nospam.skepp.be> posted :

For those who prefer fixed-width line numbering,

type file.txt | COLS ^4,10001 * 1- > file.tx1

In DOS..Win98, the two filenames can be the same; in NT, XP, maybe not.
Limits : 255 characters per line, 2^31-1 lines, IIRC. COLS via sig.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>.
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)

0 new messages