vi, adding words to the beginning of each line

  • Follow


in vi-ing a file, i have a list of lines and they have different
alphabets when they begin a new line. now i wanted to add this "more"
to the beginning of each of these line. how can i do that?

basically, i am thinking of searching for the "next line" symbol.

thanks
0
Reply yls177 4/28/2004 5:37:58 AM

In article <c06e4d68.0404272137.a533b8f@posting.google.com>, yls177 wrote:
> in vi-ing a file, i have a list of lines and they have different
> alphabets when they begin a new line. now i wanted to add this "more"
> to the beginning of each of these line. how can i do that?
> 
> basically, i am thinking of searching for the "next line" symbol.
> 
> thanks

Are you wanting to add the word 'more' to the beginning of each line?

:%s/^/more/
0
Reply Mike 4/28/2004 11:46:52 AM


Mike wrote:
>
> Are you wanting to add the word 'more' to the beginning of each line?
> :%s/^/more/

Dollars to donuts a space after that "more" will be a great idea ;^)
0
Reply dfreybur 4/28/2004 6:37:36 PM

Mike <mikee@mikee.ath.cx> wrote in message news:<108v6dcnrqo6of1@corp.supernews.com>...
> In article <c06e4d68.0404272137.a533b8f@posting.google.com>, yls177 wrote:
> > in vi-ing a file, i have a list of lines and they have different
> > alphabets when they begin a new line. now i wanted to add this "more"
> > to the beginning of each of these line. how can i do that?
> > 
> > basically, i am thinking of searching for the "next line" symbol.
> > 
> > thanks
> 
> Are you wanting to add the word 'more' to the beginning of each line?
> 
> :%s/^/more/

i dont mind doing that.. so this ^ is the trick to direct vi that for
the beginning of each line, i want to add the word more?
0
Reply yls177 4/30/2004 2:58:30 PM

>Mike <mikee@mikee.ath.cx> wrote in message
>> :%s/^/more/

yls177 <yls177@hotmail.com> wrote:
>i dont mind doing that.. so this ^ is the trick to direct vi that for
>the beginning of each line, i want to add the word more?

Not completely.  %s is the replace operator, and the two things it needs are
what to find and what to replace it with.  ^ is the regular expression anchor
for beginning-of-line.  So this is matching 0 characters at the start of a
line, and replacing the match with the word "more".
--
Mark Rafn    dagon@dagon.net    <http://www.dagon.net/>  
0
Reply dagon 4/30/2004 4:55:04 PM

yls177@hotmail.com (yls177) wrote:

>Mike <mikee@mikee.ath.cx> wrote in message news:<108v6dcnrqo6of1@corp.supernews.com>...
>> In article <c06e4d68.0404272137.a533b8f@posting.google.com>, yls177 wrote:
>> > in vi-ing a file, i have a list of lines and they have different
>> > alphabets when they begin a new line. now i wanted to add this "more"
>> > to the beginning of each of these line. how can i do that?
>> > 
>> > basically, i am thinking of searching for the "next line" symbol.
>> > 
>> > thanks
>> 
>> Are you wanting to add the word 'more' to the beginning of each line?
>> 
>> :%s/^/more/
>
>i dont mind doing that.. so this ^ is the trick to direct vi that for
>the beginning of each line, i want to add the word more?

The "s" says that you're typing a "substitute" command. The next
character (the slash) is a delimiter. The caret (^) is a regular
expression character that matches the beginning of a line, telling the
substitute command that you want to insert some there (actually
replace the beginning of each line with something, which works out to
inserting something at the beginning of each line). The last bit,
"more", is what gets inserted.

--
Tim Slattery
Slattery_T@bls.gov
0
Reply Tim 4/30/2004 4:59:50 PM

yls177 wrote:
> Mike wrote:
>
> > :%s/^/more/
>
> so this ^ is the trick to direct vi that for
> the beginning of each line

It isn't a vi trick.  It has nothing specifically to do with vi.

The caret is the regular expression symbol for the start of a
line.  ANY program that uses regular expressions will use the
caret for the start of a line.  While there are several RE
libraries available, they all use the caret.
0
Reply dfreybur 5/3/2004 5:02:34 PM

dfreybur@yahoo.com (Doug Freyburger) wrote in message news:<7960d3ee.0405030902.f63d70e@posting.google.com>...
> yls177 wrote:
> > Mike wrote:
> >
> > > :%s/^/more/
> >
> > so this ^ is the trick to direct vi that for
> > the beginning of each line
> 
> It isn't a vi trick.  It has nothing specifically to do with vi.
> 
> The caret is the regular expression symbol for the start of a
> line.  ANY program that uses regular expressions will use the
> caret for the start of a line.  While there are several RE
> libraries available, they all use the caret.



how about addign something to the end of every line? surely its not
going to V the opposite of ^ :P
0
Reply yls177 5/7/2004 10:14:08 AM

On 7 May 2004 03:14:08 -0700, yls177 
  <yls177@hotmail.com> wrote:
> dfreybur@yahoo.com (Doug Freyburger) wrote in message news:<7960d3ee.0405030902.f63d70e@posting.google.com>...
>> yls177 wrote:
>> > Mike wrote:
>> >
>> > > :%s/^/more/
>> >
>> > so this ^ is the trick to direct vi that for
>> > the beginning of each line
>> 
>> It isn't a vi trick.  It has nothing specifically to do with vi.
>> 
>> The caret is the regular expression symbol for the start of a
>> line.  ANY program that uses regular expressions will use the
>> caret for the start of a line.  While there are several RE
>> libraries available, they all use the caret.
>
>
>
> how about addign something to the end of every line? surely its not
> going to V the opposite of ^ :P
No, $ represents the end of the line.


-- 
Giraffe: a ruminant with a view.
0
Reply Bill 5/7/2004 12:34:10 PM

yls177 wrote:
> Doug Freyburger wrote>
> > yls177 wrote:
> > > Mike wrote:
>
> > > > :%s/^/more/
>
> > > so this ^ is the trick to direct vi that for
> > > the beginning of each line
>
> > It isn't a vi trick.  It has nothing specifically to do with vi.
>
> > The caret is the regular expression symbol for the start of a
> > line.  ANY program that uses regular expressions will use the
> > caret for the start of a line.  While there are several RE
> > libraries available, they all use the caret.
>
> how about addign something to the end of every line? surely its not
> going to V the opposite of ^ :P

Regular expression character that means EOL is "$".  man regexp
should be the starting point.  Learning regular expressions is
very important for SAs because they are used in everything from
filename wildcards through dozens of utilities.  Learn them in
the general case, be able to apply them everywhere.
0
Reply dfreybur 5/7/2004 5:32:40 PM

dfreybur@yahoo.com (Doug Freyburger) wrote in message news:<7960d3ee.0405070932.5e237629@posting.google.com>...
> yls177 wrote:
> > Doug Freyburger wrote>
> > > yls177 wrote:
> > > > Mike wrote:
>  
> > > > > :%s/^/more/
>  
> > > > so this ^ is the trick to direct vi that for
> > > > the beginning of each line
>  
> > > It isn't a vi trick.  It has nothing specifically to do with vi.
>  
> > > The caret is the regular expression symbol for the start of a
> > > line.  ANY program that uses regular expressions will use the
> > > caret for the start of a line.  While there are several RE
> > > libraries available, they all use the caret.
> >
> > how about addign something to the end of every line? surely its not
> > going to V the opposite of ^ :P
> 
> Regular expression character that means EOL is "$".  man regexp
> should be the starting point.  Learning regular expressions is
> very important for SAs because they are used in everything from
> filename wildcards through dozens of utilities.  Learn them in
> the general case, be able to apply them everywhere.


thanks for the advise.. will definitely get my hands on man regexp...
once i got my hands on the terminal...
0
Reply yls177 5/10/2004 9:02:09 AM

Doug Freyburger wrote:

> Regular expression character that means EOL is "$".  man regexp
> should be the starting point.  Learning regular expressions is
> very important for SAs because they are used in everything from
> filename wildcards through dozens of utilities.  Learn them in
> the general case, be able to apply them everywhere.

A good recommendation - except for one thing.  Remember that 
file-globbing ("filename wildcards") are not the same as the usual 
regular expressions.

A fairly obvious example: to the shell, a*.txt means all files that 
begin with a, but to vi, grep, and others, it means any string that 
begins with zero or more a's and ends in any character followed by a 
"txt" string.

Also note that the more advanced features are different between things 
such as sed, vi, grep, and egrep.

I recommend the UNIX in a Nutshell book - it covers all of these in a 
concise manner in a chapter, and shows a list of all of the features 
side by side for all places where they are used.
0
Reply David 5/15/2004 3:55:46 PM

11 Replies
172 Views

(page loaded in 0.132 seconds)

5/22/2013 3:17:51 AM


Reply: