LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-10-2012, 01:01 PM   #1
romeo0307
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Rep: Reputation: Disabled
Can you help with vi editor, please?


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?
 
Old 04-10-2012, 01:23 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
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.
 
Old 04-10-2012, 01:29 PM   #3
romeo0307
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-10-2012, 01:39 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Look at running sed instead. The commands are similar to ed which vim commands use.

Otherwise you could start the recorder, "q" key, and record the commands you need.
 
Old 04-10-2012, 01:41 PM   #5
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
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.
 
Old 04-10-2012, 02:07 PM   #6
romeo0307
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
guys, i have to do it the way the question asks me to do it. i can't use other things. this is for homework for my Linux class.
 
Old 04-10-2012, 02:50 PM   #7
yoK0
LQ Newbie
 
Registered: Apr 2012
Distribution: Slackware, CentOS
Posts: 29

Rep: Reputation: 0
Quote the exact exercise text in here, maybe it will help put some light on it.
 
Old 04-10-2012, 03:04 PM   #8
romeo0307
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by yoK0 View Post
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:
 
Old 04-10-2012, 03:11 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Use the -s flag in vi

Code:
       -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.
 
Old 04-10-2012, 03:11 PM   #10
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
What they may be asking is something like this:

Code:
vi -c "source  transform" basedata
Take a look at the vi man page for clarification on that option.
 
Old 04-10-2012, 03:19 PM   #11
romeo0307
LQ Newbie
 
Registered: Apr 2012
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
Use the -s flag in vi

Code:
       -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
Thanks. I think this is what I was looking for.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux distro / photo editor / music editor of choice ?? expatcanuck Linux - Newbie 1 05-04-2009 05:24 PM
LXer: Open Movie Editor: Linux Video Editor with Plot Twists LXer Syndicated Linux News 0 10-27-2008 09:50 PM
Which Editor? DaftDave Linux - Software 5 05-16-2008 06:50 PM
C++ editor onelung02 Programming 12 05-11-2005 01:51 AM
what about your editor ? black General 16 12-03-2003 08:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration