Server Administration

  Home arrow Server Administration arrow Understanding Awk in the UNIX Shell
SERVER ADMINISTRATION

Understanding Awk in the UNIX Shell
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2009-12-02

    Table of Contents:
  • Understanding Awk in the UNIX Shell
  • The structure of Awk
  • Patterns
  • Commands and variables

  •  
     

    SEARCH CODEWALKERS

    Understanding Awk in the UNIX Shell


    (Page 1 of 4 )

    So what is awk, and what does it have to do with UNIX? Plenty, as you'll soon learn. It is a tool that helps you get certain tasks done in the UNIX shell. But it's no mere tool; it's so developed that it's a programming language in its own right. Keep reading to learn how to make the most of awk.

    The core idea in the creation of any programming/scripting language is to make it as natural and as simple as possible. Still, it should allow the construction of advanced expressions for solving complex problems. The creators of the UNIX Shell script language did not forgot these two simple principles. For the sake of simplicity some parts are broken down into multiple sub-parts. Sometimes these sub-parts evolve and grow to form their own programming language.

    A prime example for this is Awk. The name "awk" comes from the starting letters of the names of the three creators: Aho - Weinberg - Kernighan. These people defined it as "awk, a pattern scanning and processing language." Besides setting a concrete purpose for the tool, this also underlines the fact that awk has its own syntax and rules. With this, it becomes a programming language on its own.

    Awk was designed to scan and process files like the .cvs, where data are organized into columns and rows. However, doing the same with any other source of organized data in this structure is a valid option (as in the case of the command ls -l). The principle behind awk is to divide an input stream into rows and records and make the changes on this.

    Last time I presented the stream editor, which accomplished the row splitting. However, compared to the sed, awk is a much more complex, powerful and more capable language. The record extraction allows us to throw away the unnecessary and process only the useful information from a file/UNIX tool.

    Awk is a scripting language, and is best for solving small everyday problems. Its three creators do not recommend it for use in big, complex problem solving. However, there are long lists of problems that can be solved with it. It also has a couple of other advantages when compared to other tools, like the sed. For instance, it can work with real numbers and follow a very C-like syntax.

    In this and a future article I will try to present it as concisely as I can without leaving out any crucial parts of awk. Remember that this article is only designed to introduce to you this language on a basic level. I do not intend to show you every corner of the scripting language. Nevertheless, this will be enough for you to use it in the everyday problems you may come across in the future.

    More Server Administration Articles
    More By Gabor Bernat

    blog comments powered by Disqus

    SERVER ADMINISTRATION ARTICLES

    - SSH Case Studies: Gateway Hosts
    - SSH Case Studies: More on Pine and SSH
    - SSH Case Studies: Pine and IMAP
    - SSH Case Studies: More on the Passive Mode
    - SSH Case Studies: Network Address Translation
    - SSH Case Studies: The Passive Mode
    - SSH Case Studies: The FTP Protocol
    - SSH Case Studies: Batch Jobs, FTP and SSH
    - SSH Case Studies: Agents and Authentication
    - SSH Case Studies
    - Server Responses to Client Communication
    - Authentication in Client/Server Communication
    - Client/Server Communication
    - Understanding Awk in the UNIX Shell
    - Stream Editor in the UNIX Shell

    Developer Shed Affiliates

     



    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap