Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
add line numbers to a text file
Name: vanderend Date: August 16, 2008 at 04:14:08 Pacific OS: - CPU/Ram: - Product: -
Comment:
I was wondering if someone would help me.
I would like to add the line numbers to a text file using a .bat! it is not possible to do this with gawk. I had the script a few years ago but I lost it. so:
Such as:
hello Sinterklaas is jarig stoomboot leuk hoor
Run the .bat and the file would look like this:
1: hello 2: Sinterklaas is jarig 3: stoomboot leuk hoor
Name: Mechanix2Go Date: August 16, 2008 at 05:07:16 Pacific
Reply:
find /n /v "" < myfile
===================================== If at first you don't succeed, you're about average.
M2
0
Response Number 2
Name: vanderend Date: August 16, 2008 at 05:39:26 Pacific
Reply:
tnnx but is it also possible don't show this [] because this is very unwanted.
I want make the list as follow;
movie001=hello
or as follow;
movie1=hello
Do you have mebay another trick for me?
thanx.
0
Response Number 3
Name: IVO Date: August 16, 2008 at 07:00:36 Pacific
Reply:
@echo off & setlocal EnableDelayedExpansion set count=0 for /F "tokens=* delims=" %%j in (myfile) do ( set /A count+=1 echo.!count!: %%j >> newfile ) :: End_Of_Batch
0
Response Number 4
Name: ghostdog Date: August 16, 2008 at 10:03:27 Pacific
Reply:
>> it is not possible to do this with gawk. It IS possible to do this in gawk. Its different from "not possible to do this with gawk because environment doesn't allow"
Anyway, here's an gawk solution nonetheless.
{print NR":"$0}
save as script.awk and on command line (or batch)
c:\test> gawk -f script.awk file
0
Response Number 5
Name: FishMonger Date: August 16, 2008 at 13:55:44 Pacific
Reply:
It can also be done with a perl command without the need of the intermediate script file that gawk needs.
c:\test>perl -ne "print qq/$.: $_/" file.txt
0
Response Number 6
Name: ghostdog Date: August 16, 2008 at 18:01:19 Pacific
Reply:
an intermediate script file is NOT needed actually as gawk can be used like what you did with Perl, a one liner.
c:\test> gawk "{print NR\":\"$0}" file
0
Response Number 7
Name: vanderend Date: August 17, 2008 at 07:33:38 Pacific
Reply:
tnnx a lot! I have it done with dos.
0
Response Number 8
Name: Mechanix2Go Date: August 17, 2008 at 22:19:31 Pacific
Reply:
"tnnx a lot! I have it done with dos."
I doubt it, but I'll stay tuned.
===================================== If at first you don't succeed, you're about average.
Summary: I was wondering if someone would help me. I would like to add the line numbers to a text file using a .bat Such as: hello hello hello Run the .bat and the file would look like this: 1: hello 2: hello ...
Summary: I am trying to creat a database file to a .txt file. printf("%f> %d %d %d %d %d %d ",time,clk33,clk66,clk132,clk33,clk33,word0); The above string will print to a string several numbers which I need...
Summary: I'm trying to write a VB script for an HTA to go with a batch file that has already been written. The batch file currently prompts the user for several port numbers on a switch (one at the time). I'...