Unix administration - vi, adding words to the beginning of each line

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > May 2004 > vi, adding words to the beginning of each line





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author vi, adding words to the beginning of each line
yls177

2004-04-28, 1:34 am

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
Mike

2004-04-28, 8:35 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/
Doug Freyburger

2004-04-28, 2:34 pm

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 ;^)
yls177

2004-04-30, 11:35 am

Mike <mikee@mikee.ath.cx> wrote in message news:<108v6dcnrqo6of1@corp.supernews.com>...
> In article <c06e4d68.0404272137.a533b8f@posting.google.com>, yls177 wrote:
>
> 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?
Mark Rafn

2004-04-30, 1:35 pm

>Mike <mikee@mikee.ath.cx> wrote in message

yls177 <yls177@hotmail.com> wrote:[vbcol=seagreen]
>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/>
Tim Slattery

2004-04-30, 1:35 pm

yls177@hotmail.com (yls177) wrote:

>Mike <mikee@mikee.ath.cx> wrote in message news:<108v6dcnrqo6of1@corp.supernews.com>...
>
>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
Doug Freyburger

2004-05-03, 1:39 pm

yls177 wrote:
> Mike wrote:
>
>
> 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.
yls177

2004-05-07, 6:34 am

dfreybur@yahoo.com (Doug Freyburger) wrote in message news:<7960d3ee.0405030902.f63d70e@posting.google.com>...
> yls177 wrote:
>
> 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
Bill Marcum

2004-05-07, 11:01 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>...
>
>
>
> 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.
Doug Freyburger

2004-05-08, 10:40 am

yls177 wrote:
> Doug Freyburger wrote>
>
>
>
>
>
> 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.
yls177

2004-05-10, 5:44 pm

dfreybur@yahoo.com (Doug Freyburger) wrote in message news:<7960d3ee.0405070932.5e237629@posting.google.com>...
> yls177 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.



thanks for the advise.. will definitely get my hands on man regexp...
once i got my hands on the terminal...
David Douthitt

2004-05-15, 12:34 pm


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.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com