vi, adding words to the beginning of each line

Ask a Question related to Linux / Unix Administration, Design and Development.

  1. #1

    Default vi, adding words to the beginning of each line

    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
    yls177 Guest

  2. Similar Questions and Discussions

    1. Getting line breaks between words
      Is there a way to have InDesign wrap to a new line between words? Here's why ... I'm working on a VDP (Variable Data Printing) project of an eye...
    2. What does a semicolon do at the beginning of a line?
      Was browsing the documentation on reading a configuration file and found this. What does a semicolon do at the beginning of a line? ; <?php DO...
    3. Add text to beginning every line
      Hi Hope someone can help with this. I used to be able to do it, but now have forgotten. I want to prepend some text to every line in a file. The...
    4. replace words with bold words
      Hello I was wondering if you guys could help me solve this using reg exp, i have a searchpage and a variable keywords that holds a number of...
    5. Write line at beginning of file?
      Eric Pement <pemente@northpark.edu> wrote: What version of perl are you referring to?
  3. #2

    Default Re: vi, adding words to the beginning of each line

    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/
    Mike Guest

  4. #3

    Default Re: vi, adding words to the beginning of each line

    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 ;^)
    Doug Freyburger Guest

  5. #4

    Default Re: vi, adding words to the beginning of each line

    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?
    yls177 Guest

  6. #5

    Default Re: vi, adding words to the beginning of each line

    >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 [email]dagon@dagon.net[/email] <http://www.dagon.net/>
    Mark Rafn Guest

  7. #6

    Default Re: vi, adding words to the beginning of each line

    [email]yls177@hotmail.com[/email] (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
    [email]Slattery_T@bls.gov[/email]
    Tim Slattery Guest

  8. #7

    Default Re: vi, adding words to the beginning of each line

    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.
    Doug Freyburger Guest

  9. #8

    Default Re: vi, adding words to the beginning of each line

    [email]dfreybur@yahoo.com[/email] (Doug Freyburger) wrote in message news:<7960d3ee.0405030902.f63d70e@posting.google.c om>...
    > 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
    yls177 Guest

  10. #9

    Default Re: vi, adding words to the beginning of each line

    On 7 May 2004 03:14:08 -0700, yls177
    <yls177@hotmail.com> wrote:
    > [email]dfreybur@yahoo.com[/email] (Doug Freyburger) wrote in message news:<7960d3ee.0405030902.f63d70e@posting.google.c om>...
    >> 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.
    Bill Marcum Guest

  11. #10

    Default Re: vi, adding words to the beginning of each line

    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.
    Doug Freyburger Guest

  12. #11

    Default Re: vi, adding words to the beginning of each line

    [email]dfreybur@yahoo.com[/email] (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...
    yls177 Guest

  13. #12

    Default Re: vi, adding words to the beginning of each line


    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.
    David Douthitt Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139