regexp with line numbers

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

regexp with line numbers

Justin Randall-2
Hi,

I have a file with a few hundred lines, and each line begins with a '#' character.  I
want to replace it with the line number and a period. For example I want the fisrt line
to go from

     # The first line stuff.

to
     1. The first line stuff.

and so on for each line in the file.  Does anybody know a good regexp for this?  I've
seen a could of excellent regexps on this email list, but I can't think of one that did
incremental replacement like I'm looking for.  

Cheers,
Justin


               
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: regexp with line numbers

Tim Chase-2
> I have a file with a few hundred lines, and each line begins
> with a '#' character.  I want to replace it with the line
> number and a period. For example I want the fisrt line to go
> from
>
>      # The first line stuff.
>
> to
>      1. The first line stuff.

Here's where

        :help sub-replace-special

comes in handy.  As you've got every line (there are not
gaps...every line gets a number) you can use

        :%s/#/\=line(".")."."

which should do the trick.

-tim




Reply | Threaded
Open this post in threaded view
|

RE: regexp with line numbers

yahalome
In reply to this post by Justin Randall-2
You can use tcldo:
tcldo set line $lnum[string range $line 1 end]    

Yahalom Emet
Ashrait Team Leader
Xor Technologies
phone: 04-6619166
fax: 04-6619054
e-mail: [hidden email]
web: http://www.xortechnologies.com


-----Original Message-----
From: Justin Randall [mailto:[hidden email]]
Sent: Wednesday, September 21, 2005 3:21 PM
To: [hidden email]
Subject: regexp with line numbers

Hi,

I have a file with a few hundred lines, and each line begins with a '#'
character.  I
want to replace it with the line number and a period. For example I want the
fisrt line
to go from

     # The first line stuff.

to
     1. The first line stuff.

and so on for each line in the file.  Does anybody know a good regexp for
this?  I've
seen a could of excellent regexps on this email list, but I can't think of
one that did
incremental replacement like I'm looking for.  

Cheers,
Justin


               
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com