Viewing and Editing Text Files

team bbl


Text files are files that contain only text characters, with no formatting information. Text files contain information stored in ASCII code, a code that is understood by most applications. HTML files, program source code, and many Linux configuration files are stored in text files. Although you can view and edit the contents of text files with a word processor, it's generally quicker and simpler to open them in a text editoran application that has only the features necessary to edit text. Some text editors are:

  • Kate: A simple basic text editor with a GUI interface, very similar to Notepad. Kate is discussed in full detail in Chapter 18.

  • KWrite: A text editor similar to Kate, with a few more useful features, such as a spell checker. KWrite is the default text editor for KDE. When you double-click a text file, it opens in KWrite.

  • Emacs: A popular editor, developed by GNU, with advanced features for programmers.

  • vi: A command-based text editor, suitable for use at the command line. vi is installed on every Linux and UNIX system, regardless of what other text editors are installed. vi is described in detail in Chapter 18. Many Linux distributions provide an updated version of vi called vim. Any commands that work in vi also work in vim.

You can look at the contents of a file at the command line without opening the file in a text editor with the command:

 cat filename 

The entire file contents display on the screen at once. You can display the contents one screen at a time with the following command:

 less filename 

Output pauses after one screen displays. Press <spacebar> to display the next page. Press <q> to quit the command, stopping the output.

Linux provides two applications for automating repetitive text editing:

  • sed: A powerful, fast search and replace utility. Your search term can be a pattern (regular expression, discussed in Appendix A). sed can process many large files in seconds.

  • gawk: A simple, limited purpose scripting language. gawk processes each line in the file, rearranging, removing, and/or adding text as directed.

    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net