Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to add line numbers to a text file through a batch. any thoughts?
I have this:
SET /a count=0
FOR /f %%f in (%1) DO CALL :countLines %%f
GOTO :showLineCount:countLines
@ECHO %count%
SET /a count+=1
GOTO :end:showLineCount
ECHO %count%
:end
But i'm wanting to add the number to the beginning any give text file, not just count the numbers

What I am thinking is parse each line of your text file to a new file for each of them, while adding %count% before each line. Then type all those files to your main file, then do something like
del line*.txt
to get rid of the files created from this file.
crappy OEM comptuers...

So, I almost have what I am needing. Here is what I am working with now. It counts, skips the first line, and types...but only the first word of the file.
---------------
SET /a count=0FOR /f "TOKENS=* skip=1" %%f in ('type %1') DO CALL :countLines %%f
GOTO :end:countLines
@ECHO %count% %1
SET /a count+=1
GOTO :end:end
---------------
Using the text:
Mary had a little lamb
Its fleece was white as snow
And every where that Mary went
The lamb was sure to gohere is what I get
0 Its
1 And
2 TheIt's not typing the entire line, just the first word.

if you can download and install gawk for windows here..: http://gnuwin32.sourceforge.net/pac...
save the below as script.awk
NR>1{print NR-1":"$0}on the command line:
c:\test> more file
Mary had a little lamb
Its fleece was white as snow
And every where that Mary went
The lamb was sure to goc:\test> gawk -f script.awk file
1:Its fleece was white as snow
2:And every where that Mary went
3:The lamb was sure to go

ghostdog...that is exacly what I was needing. gawk.exe is not dependant on anything else, and it did the job perfectly.
the purpose of the batch was to ping server or workstation names within a file and give me a final output in a csv like this
0, machine name, ip
1, machine name, ip
2, machi.......thnx a mill...

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |