|
Home > Archive > Unix Shell > January 2006 > Vi command to insert at the begin of a line for lines in a file
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 command to insert at the begin of a line for lines in a file
|
|
| gpaladi@gmail.com 2006-01-18, 5:55 pm |
| 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?
| |
|
|
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
| |
| gpaladi@gmail.com 2006-01-18, 5:55 pm |
| Thank you so much Sashi.
| |
| Chris F.A. Johnson 2006-01-18, 5:55 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
| |
| libdave@gmail.com 2006-01-18, 5:55 pm |
| :%s/^/new stuff/
| |
|
| 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
|
|
|
|
|