Vi / vim - Insert a external command response


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vi / vim - Insert a external command response
# 1  
Old 02-08-2017
Vi / vim - Insert a external command response

I would like to execute and external command and insert it into a particular area of the file I am editing. Note that I have the ORIGINAL AT&T vi training doc dated 1987. Doesnt explain it.

As an example, in a vi editor I have
Quote:
Now is the time for all good men to come to the aid of their country.
I would like the result :
Quote:
Now is the time for /home/popeye all good men to come to the aid of their country.
After executing the following from vi command mode :
Code:
:r!echo $HOME

I did try to join. But the external command response is joined to the end of the existing text.

Ill also look at join and yank and paste options

Thanks in advance!
# 2  
Old 02-08-2017
Try the following sequence of commands:
Code:
/ all<carriage-return>

(where <carriage-return> is entered by hitting the "return" key) This will position the cursor on the space where you want to insert your text.
Code:
s<carriage-return><carriage-return><ESC>

(where <ESC> is entered by hitting the escape key) This will create an empty line where we can insert the output from an external command and leave the cursor on the line after the empty line we just created.
Code:
.-1!echo $HOME<carriage-return>

which will replace the contents of the empty line above where where are sitting with the output produced by the command echo $HOME and leave the cursor on the text that was just replaced.
Code:
kJJ

to move up one line and join the next two lines to that line.

Then continue with other changes you want to make to the file...

PS: Note that the above instructions assume that your cursor is located at the start of the line you mentioned in your post. If that is not where you are sitting, the initial search pattern may need to be more extensive to be sure you locate the proper spot on the proper line.

Last edited by Don Cragun; 02-08-2017 at 02:03 PM.. Reason: Add PS.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell vim defaulting to Insert or Command mode

On a daily basis I need to SSH into several different RHEL servers using Putty. On some of the servers, if I up arrow to get a previous command, it automatically starts in Input Mode, so if I press up arrow, then 'x' it will type the letter x at the end of the command line. On other servers, it... (4 Replies)
Discussion started by: derndingle
4 Replies

2. Shell Programming and Scripting

WGET command retrying to get response

Hi , Iam using " WGET " command to hit the URL,i.e. servlet url. I can trigger the servlet using wget but when servlet is not responding this command retries automatically until it get the positive response from the server. So this script is running for more than 8 hrs to get the positive... (2 Replies)
Discussion started by: vinothsekark
2 Replies

3. Shell Programming and Scripting

[awk] - how to insert an external variable

I want to incorporate the variable in the for statement as a column of my processed file. In the INCORRECT example below, it is $i which corresponds to the i in my for loop: for i in x86_64 i686; do awk '{ print $1" "$4" "$5" "$i }'awk $file-$i > processed-$i.log doneThanks! (3 Replies)
Discussion started by: graysky
3 Replies

4. UNIX for Dummies Questions & Answers

Vim external command output to new buffer

Hi, From inside Vim, I'm looking for a way to use the contents of the current buffer, pass it to an external executable, and then return the output from the executable into a new Vim buffer. I know that I can do something like %!<executable>, but that will overwrite the contents of the... (3 Replies)
Discussion started by: konfushus
3 Replies

5. Shell Programming and Scripting

scp command and no response

I should trasfer some files by xxx.xxx.xxx.xxx to local host. In order to check the function works i tried to transfer a single file and I typed: scp -P 21 username@xxx.xxx.xxx.xxx:/filename.nas /filename.nas At this point i haven't response anch i have to type CTRL+C to return to... (2 Replies)
Discussion started by: andreac81
2 Replies

6. Shell Programming and Scripting

Insert external variable in a AWK pattern

Dear all, ¿How can i insert a variable in a AWK pattern? I have almost succeeded in solving a puzzle with AWK but now i want to make a script. Let me explain. cat file.txt | awk 'BEGIN {RS="\\n\\n"} /tux/ { print "\n"$0 }' I know that this command makes right what i want to do, but mi... (8 Replies)
Discussion started by: antuan
8 Replies

7. UNIX for Dummies Questions & Answers

vi/vim insert behaviors

While using vi or vim on different boxes, I experience different behaviors when I'm inserting (i) or writing on a new line (o). On the Linux box, I can insert and delete with my backspacekey while in the insert mode. It acts a little more like pico,nedit, etc. On the SunOS box, it's a headache... (3 Replies)
Discussion started by: mrwatkin
3 Replies

8. UNIX for Dummies Questions & Answers

'less' command response is garbled

Helo , I m using RHEL 4. If I run 'ls -laF | more', response is properly display. but when I run If I run 'ls -laF | less', the response is garbled what to do to remove this? Regards, Amit (4 Replies)
Discussion started by: amitpansuria
4 Replies

9. AIX

VI questions : mass changes, mass delete and external insert

Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ? I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them. Also, can... (1 Reply)
Discussion started by: Browser_ice
1 Replies

10. Shell Programming and Scripting

insert escape charactor within VIM

Hi, I need to send "^[" command to the buffer. I tried to use insert within VIM and press 'ctrl' key and then '^' and '[' key. but it didn't work. Does anyone know how to do it? Thanks a lot! Julie (2 Replies)
Discussion started by: cin2000
2 Replies
Login or Register to Ask a Question