Author Topic: Prepend Line Number  (Read 488 times)

texpic

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Prepend Line Number
« 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


Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Prepend Line Number
« Reply #1 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.

Graeme

  • Senior Community Member
  • Posts: 2366
  • Hero Points: 313
Re: Prepend Line Number
« Reply #2 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.

Marcel

  • Senior Community Member
  • Posts: 222
  • Hero Points: 26
Re: Prepend Line Number
« Reply #3 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.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2821
  • Hero Points: 426
Re: Prepend Line Number
« Reply #4 on: April 08, 2019, 02:45:13 pm »
FWIW, SlickEdit took about a two minutes, on the test file I put together.