[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: vi globally append question

On Thu, Jul 15, 2004 at 10:24:32AM -0400, Rick Pasotto wrote:
| On Thu, Jul 15, 2004 at 06:49:20AM -0700, Sean wrote:
| > hi all,
| > 
| > i have a file like;
| > 
| > # one 123
| > 
| > and i would like to APPEND a # at the beginning of each line
| 'append' means to add to the end. It is impossible to append to the
| beginning of something.

Sean - you meant 'prepend'.

| > which is not started with a # . how can i do it with vi or ed, so far,
| > i 've tried;
| > 
| > :%s/^[a-z]:[0-9]/#/g
| > 
| > but this would CHANGE the first character of each line to a hash, pls
| > help.
| :%g/^[^#]/s/^/#/

I ought to learn that construct.  It might come in handy sometimes!

Not being familiar with that one, I would have used a backreference.
Here's the example, for those who want to learn this feature as well.

(it substitutes the first character of a line with '#' followed by
the original first character)

One OS to rule them all, one OS to find them,
One OS to bring them all and in the darkness bind them,
In the Land of Redmond, where the Shadows lie.
www: http://dman13.dyndns.org/~dman/            jabber: dman@dman13.dyndns.org

Attachment: signature.asc
Description: Digital signature

Reply to: