f



Vi command to insert at the begin of a line for lines in a file

What is the "Vi" command to insert some line of code at the beginning
of all the lines in a file globally at one shot?

0
gpaladi
1/18/2006 8:48:12 PM
comp.unix.shell 15484 articles. 2 followers. Post Follow

5 Replies
761 Views

Similar Articles

[PageSpeed] 12

gpaladi@gmail.com wrote:
> What is the "Vi" command to insert some line of code at the beginning
> of all the lines in a file globally at one shot?

In command mode, 
:%s/^/insert_your_code_here/ 
Sashi

0
Sashi
1/18/2006 8:57:08 PM
Thank you so much Sashi.

0
gpaladi
1/18/2006 9:00:21 PM
On 2006-01-18, gpaladi@gmail.com wrote:
> What is the "Vi" command to insert some line of code at the beginning
> of all the lines in a file globally at one shot?

  Since this is a shell newsgroup, not a vi (or other editor)
  newsgroup, I'll give you a shell method:
 
sed "s/^/Text to insert/" FILE > tempfile &&
mv tempfile FILE

  If you want, you can probably run it from within vi.

-- 
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence
0
Chris
1/18/2006 9:03:06 PM
:%s/^/new stuff/

0
libdave
1/18/2006 9:11:52 PM
gpaladi@gmail.com wrote:
> What is the "Vi" command to insert some line of code at the beginning
> of all the lines in a file globally at one shot?

If you want to insert many lines in Vi the you might want to put those
code in a separate file, say 'some.code', and use the command:

:g/^/ -r some.code

Change the '^' to '.' if you only want to process non-blank lines.

HTH.
-- 
Regards,
hq00e

0
hq00e
1/19/2006 5:31:42 AM
Reply: