UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
Have you ever found yourself in a situation where you had to edit multiple files in a directory or a system? The vi editor can handle more than one file at a time. It is possible to pipe multiple files into it and edit each one.
Flavors: AT&T, BSD
Shells: All
Syntax:
vi `ls [-1] file`
You can take a listing of a directory and pass it through to the vi editor. When the editor is launched, all you have to do is switch to each file that is waiting to be edited.
If there is a directory with a series of scripts, and you need to modify a variable setting in each of the scripts, you can send the list of files to the editor all at one time.
rocket 35% ls -l total 21 -rw-r--r-- 1 ugu 220 Jan 1 01:25 README.txt -rw-r--r-- 1 ugu 660 Jan 1 01:27 config.ini -rw-r--r-- 1 ugu 8862 Jan 1 01:28 mondisk.sh -rw-r--r-- 1 ugu 555 Jan 1 01:27 monreport.sh -rw-r--r-- 1 ugu 8263 Jan 1 01:28 monsys.sh rocket 36% vi `ls -1 *.sh`
All three files in this case are loaded in to the vi editor. Make the necessary changes, and write ( :w) the changes out, but don't quit the editor. To access each file that is loaded, use the next ( :n) command from the command line mode.
Flavors: AT&T, BSD
Shells: All
Syntax:
vi `find path -print [-type f] | grep pattern` vi `find path -name pattern -print`
This is another variation of getting multiple files into vi for editing. In these commands, the capability of multiple files in multiple directories can be edited.
If you have a program with source that is made up of a series of directories, but you have configuration files or makefiles in each of the subdirectories that need some variable modified, sending the results of the files found to the vi editor would speed things up tremendously for you.
rocket 37% find . -print | grep Makefile
./src/sun/Makefile ./src/sgi/Makefile ./src/dec/Makefile ./src/ibm/Makefile
rocket 38% vi `find . -print | grep Makefile`
or
rocket 38% vi `find . -name Makefile -print`
All four files are loaded into the vi editor. After you make the necessary modifications, write ( :w) the changes out, but don't quit the editor. Each of the other files that were loaded can be accessed using the next ( :n) command from the command line mode.
The amount of time it takes to load a file, make changes, exit the file, and load the next one is such a waste of time. Loading all the files at once, making the changes, and writing each out are great timesavers.
I typically find myself performing edits on multiple files on a daily basis. So much so that I created two aliases in my login scripts ( vils and vif) that get the files I need by simply masking the files to the aliases I set up:
alias vils 'vi `ls -1 !*`' alias vif 'vi `find . -print -type -f | grep \!*`'
I trimmed down not only my editing time but the length of the command line as well. For me, every little bit helps.
rocket 39% vils *.sh rocket 40% vif Makefile
Man pages:
ls, find, grep, vi
UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.