SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: texpic on April 05, 2019, 12:58:05 PM

Title: Prepend Line Number
Post by: texpic on April 05, 2019, 12:58:05 PM
I have a 10,000,000 row file; need to add a line (row) number.

Data Before:

MyComapny, Inc
First Last Place, Suite 1000
Dallas, Texas 77777
214-000-0000

Data After:

0000000001 MyComapny, Inc
0000000002 First Last Place, Suite 1000
0000000003 Dallas, Texas 77777
0000000004 214-000-0000

Title: Re: Prepend Line Number
Post by: Lee on April 05, 2019, 01:08:19 PM
Select All Lines, then use Edit > Other > Enumerate, set the Start: 1, Increment: 1, and set Pad to however many digits you need there.  Never tried it with 10 million lines before, but should do the job.
Title: Re: Prepend Line Number
Post by: Graeme on April 06, 2019, 04:18:05 AM
mmm, let's see.  At 20 characters per line on average that's 200 million characters.  To insert 11 characters at the start of each line and the whole file is in one great big buffer, that's ten million insertions with each insertion copying an average of 100 million characters.  Let's optimistically say the hardware can copy 10000 characters per microsecond (how many GHz is that), copying 100 million characters takes ten seconds.  Ten seconds times ten million is about three years...  There must be a quicker way.
Title: Re: Prepend Line Number
Post by: Marcel on April 06, 2019, 04:15:59 PM
Sorry, I couldn't resist  ;):

perl -ne "printf \"%%08d %%s\", $., $_" < text.unnumbered > text.numbered

About 13 secs for the 10Mio lines.
Title: Re: Prepend Line Number
Post by: Dennis on April 08, 2019, 02:45:13 PM
FWIW, SlickEdit took about a two minutes, on the test file I put together.