Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to automate a file edit process using vi and a file of commands called "script." Which command would invoke vi on a data file called "data" but which would automatically apply the commands in "script" to the "data" file without further intervention from me?
I'm not sure I follow what you are trying to accomplish. First, vi or vim is not used for automatic updates. Coding languages like bash, python, perl, C, etc.. are placed into a script to do the work you want. If you are wanting to make modification to a file python or bash is a good way to go. If you can respond with a little more specifics we can be of more help.
well, while in vi editor, you can enter text from another file into a current file with ":r filename"
this is kind of the same, but they want you to execute commands from a script file on a data file.
read the question again please. that's what is being asked of me and i don't know what to do here either.
Right, so if you need to execute a script file on a data file you should use bash or python or a similar programming language. vi or vim is a tool used if you are making the changes yourself. Yes you can read outside files inside of vi, the :r reads the file and appends the contents after the current line.
Quote the exact exercise text in here, maybe it will help put some light on it.
i did pretty much copy the text here. but anyway, here is the text:
Quote:
You wish to automate a file edit process using vi and a file of commands called ‘transform’. Write the command to invoke vi on a data file called ‘basedata’ but which automatically applies the commands in ‘transform’ to the data file (basedata) without further intervention from you:
-s {scriptin}
The script file {scriptin} is read. The characters in the
file are interpreted as if you had typed them. The same
can be done with the command ":source! {scriptin}". If the
end of the file is reached before the editor exits, further
characters are read from the keyboard.
I use it from time to time, it's pretty straight forward. For example, if you wanted to replace the 27th character on the 4th line in your ASCII file with an "R", you would create a script with the following contents:
Code:
:4
27|rR:wq
and then run:
Code:
vi file -s script
Last edited by suicidaleggroll; 04-10-2012 at 03:17 PM.
-s {scriptin}
The script file {scriptin} is read. The characters in the
file are interpreted as if you had typed them. The same
can be done with the command ":source! {scriptin}". If the
end of the file is reached before the editor exits, further
characters are read from the keyboard.
I use it from time to time, it's pretty straight forward. For example, if you wanted to replace the 27th character on the 4th line in your ASCII file with an "R", you would create a script with the following contents:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.