![]()
![]()
![]()
![]()
Editing Text Files in UNIX
Most bioinformatics work involves messing around with text files. DNA and protein sequences, databases, resuls of similarity searches and multiple alignments - they are all stored on the computer as ordinary ASCII text files. So you need to learn how to read, write, and edit these text files. This requires that you get familiar with a text editor program
There are many different text editors available for UNIX computers. Most UNIX systems provide several choices. We will only discuss the emacs text editor in this class because it is fairly simple to use, it is very common on UNIX systems, and it is free. No matter where you get a UNIX account in the future, you are likely to have emacs at your disposal. Some other common UNIX text editors include jed, pico, and vi.
A. What is emacs?
The full name of the emacs program is: "GNU emacs, the Extensible, Customizable, Self-Documenting, Real-time Display Editor." It is used primarily on UNIX systems, but there are versions for VMS, MS-DOS, Windows-95, and Windows-NT systems.
emacs is free software produced by the Free Software Foundation (Boston, MA) and distributed under the GNU General Public License. This has a lot in common with the Open Source Linux software phenomenon.
I should also add that "GNU" is an acronym for "GNU is Not UNIX" and that the G in GNU is not silent.
A text editor is like a word processor on a personal computer, except that it does not apply formatting styles (bold, italics, different fonts etc.).
Emacs is a visual editor, which means that you have a representation of your entire document on your screen, and you can move around freely, editing any part of the document you wish. Emacs also provides some word-processor like abilities. For instance, you can look at or edit several files at once and move blocks of text between them.
The output files of many molecular biology programs are text; thus, emacs provides an excellent way to view this output, freely scroll up and down, jump back to the beginning, etc.
B. Starting emacs
To start emacs, at the $ command prompt, just type:
emacs
If you want to edit a specific file, type:
emacs filename
where filename is the name of the file that you want to edit.
When emacs is launched, it opens either a blank text window or a window containing the text of an existing file.
![]()
The display in emacs is divided into three basic areas.
The top area is called the text window. The text window takes up most of the screen, and is where the document being edited appears.
Below the text window, there is a single mode line. The mode line gives information about the document, and about the emacs session.
The bottom line of the emacs display is called the minibuffer. The minibuffer holds space for commands that you give to emacs, and displays status information.
Emacs uses control and escape characters to distinguish editor commands from text to be inserted in the buffer. In this document, the notation Control-x means to hold down the control key, and type the letter x. You don't need to capitalize the x, or any other control character. ESCAPE->-X means to press the escape key down, release it, and then type x.
To exit emacs and return to the UNIX shell, type Control-x->-Control-c If you have made changes to the buffer since the last time you saved it to disk, emacs will ask you if you want to save. Type y for yes, or n for no.
NOTE: When you edit a file in emacs, you're not really editing the file itself, as it sits on the file server's hard disk. Instead, emacs makes a copy of the file, and stores the copy in an area of RAM memory called a buffer. All the changes you make to the file are applied to the buffer. When you save the file, emacs writes the contents of the buffer to the disk. Since the buffer is part of your current terminal session, it disappears if your session crashes. Thus, you should use the save command often, copying your current buffer to disk. This is really no different than using MS Word on a Mac or PC.
Getting help for emacs
emacs has its own built-in tutorial, just type Control-h t
Here are some links to online tutorials for emacs:
Getting Started with Emacs by Johnathon Poole, University College London, Dept. of Computer Science
Emacs Beginner's HOWTO
http://linuxcentral.com/linux/LDP/HOWTO/Emacs-Beginner-HOWTO.html
Getting Started With the Emacs Screen Editor
[This is a PDF file - requires Adobe Acrobat]
University Computing Service, University of Leeds
http://www.leeds.ac.uk/iss/documentation/beg/beg6.pdf
The official GNU Emacs Manual
http://www.gnu.org/manual/emacs/html_chapter/emacs_toc.html
![]()
![]()
![]()
![]()
Using Computers for Molecular Biology
Stuart M. Brown, Ph.D, RCR, NYU Medical Center Comments to: browns02@mcrcr.med.nyu.edu