Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing external command from within vi 2

Status
Not open for further replies.

olded

Programmer
Oct 27, 1998
1,065
US
Hi:

I seem to remember being able from within vi being able to execute an external command, and have the results of that command appear in vi.

Does anybody no how to do this.

Regards,

Ed
 
:!ls

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Or to insert the output of a command into your file

:r !ls

You can also send part of your file to a command and replace that text with the output of the command
e.g. to format the current paragraph

!)fmt

This sends the rest of the current paragraph to the fmt command and replaces that paragraph with the output from the fmt command

CaKiwi
 
nice one, CaKiwi!

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks Vlad!

A minor errorin my post - !)fmt formats the current sentence, !}fmt is needed to format the current paragraph

CaKiwi
 
Thanks guys!

Sorry I really posted this question ikn the wrong forum.

Regards,


Ed
 
I often grab some range or the entire body within vi and apply shell stuff to it.

e.g.

# keep 2 of pipe-delimited columns
:/start/,/end/!awk 'BEGIN{FS=OFS="|"}{print $2,$3}'

# or
:%!cut -d"|" -f2,3

# add 5 to each of list of values
:%!while read value; do expr $value + 5; done

etc... Mostly I use this with the sort command on ascii dumps of data.



Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top