Perl Basics   «Prev  Next»

Lesson 7Perl's text heritage
ObjectiveLearn how awk and sed influenced the development of Perl.

The Influence of awk and sed on the Development of Perl

The development of Perl, a high-level, general-purpose, interpreted, and dynamic programming language, is steeped in the rich history of Unix text processing utilities such as awk and sed. Perl, created by Larry Wall in 1987, was designed to embrace the pragmatism and functionality of these utilities, consolidating their text processing capabilities and augmenting them with advanced programming constructs. Understanding the impact of awk and sed on Perl necessitates exploring their fundamental characteristics and functionality.

awk and sed: Pioneers of Text Processing

What is awk?

awk is a pattern-directed scanning and processing language. Created by Aho, Weinberger, and Kernighan in the 1970s, awk is tailored for text processing and data extraction, especially in formatted text files. Its programming paradigm enables users to specify patterns and actions to be performed on matched patterns, thus automating the parsing and processing of text data.

What is sed?

sed, the stream editor, operates by applying predefined editing commands on a stream of text, making it a potent tool for automated text editing and transformation. Developed by Lee McMahon in the early 1970s, sed facilitates the automated editing of text files without user intervention, enhancing efficiency and accuracy in text processing tasks.


Perl: The Integration and Enhancement of awk and sed

Perl’s design ethos inherently incorporates and augments the capabilities of awk and sed. This integration is manifest in the following dimensions:

Unified Text Processing Language

Perl unifies the functionalities of awk and sed, providing a single language that comprehensively handles text processing tasks. This unification eliminates the need for scripting in multiple languages, ensuring seamless and efficient text manipulation and processing.

Enhanced Regular Expression Engine

Perl features an advanced and efficient regular expression engine, building upon the capabilities of awk and sed. The enhanced regular expression engine in Perl enables more complex pattern matching and text manipulation, bolstering the efficiency and scope of text processing operations.

Comprehensive Programming Constructs

Beyond text processing, Perl integrates comprehensive programming constructs, offering functionalities akin to fully-fledged programming languages. This integration empowers users to perform complex tasks beyond the capabilities of awk and sed, including system administration, web development, and network programming.
In summation, the development of Perl is intrinsically intertwined with the legacy of awk and sed. By integrating and enhancing the text processing capabilities of these Unix utilities, Perl has emerged as a robust and versatile language, proficient in handling a wide array of computing tasks beyond text processing. The influence of awk and sed on Perl epitomizes the evolutionary trajectory of programming languages, underscoring the imperative of learning from historical context and existing tools to foster innovation and advancement in software development.

Perl's text heritage influenced by awk and sed

Some of the most significant roots of Perl are in the Unix tools called awk and sed. awk (named after its inventors, Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan) is a simple language for searching and processing text files. It is described in the book, The AWK Programming Language (Addison-Wesley, 1988). sed is an in-line stream editor that has been a part of Unix for many years. It is used for changing the contents of files, usually as part of a pipeline of commands.
Both awk and sed are usually used as filters, and Perl is commonly used that way as well.
Question: What's a filter? In this context, a filter is a program that takes its input, changes it a little, and gives the result as output. For example, if you wanted to find the process numbers of all the HTTP daemons on your system, you could use awk to filter the output of the ps command like this:

How did awk and sed influence the creation of the Perl Programing Language?

Awk and Sed are two Unix tools that were popular in the 1980s and early 1990s, and they were a major influence on the creation of the Perl programming language. Both Awk and Sed were used for text processing and manipulation, and they were powerful tools for many common tasks. However, they had limitations, such as a lack of control structures and a lack of support for complex data structures.
Perl was designed to address these limitations and provide a more powerful and flexible tool for text processing. Larry Wall, the creator of Perl, was a Unix system administrator and a user of Awk and Sed, and he wanted to create a language that combined the strengths of these tools with other scripting and programming languages. As a result, Perl incorporates many features from Awk and Sed, such as regular expression support and text-processing capabilities, and adds many other features that make it a general-purpose programming language.
In this way, Awk and Sed were a major influence on the design and creation of the Perl programming language, and they played an important role in its evolution into a versatile and widely used language.


ps -ax | awk '/httpd/ { print $1 }'

Or, if you wanted to change all the occurrences of "Jefferson" to "Franklin" in an HTML file (say, a miswritten biography--I've seen it happen!), you could use sed like this:
sed 's/Jefferson/Franklin/e' <history.html> history2.html

Both of these tasks can also be done with perl:
ps -ax | perl -ane 'print "$F[0]\n" if /httpd/'

perl -pe 's/Jefferson/Franklin/g' <history.html >history2.html

The major common heritage of both awk and sed is in their use of regular expressions.