You must have a basic understanding of GNU/Linux operating system and shell scripting.

Similar documents
This is a brief tutorial that explains how to make use of Sqoop in Hadoop ecosystem.

This tutorial has been prepared for beginners to help them understand the basic functionalities of Gulp.

This is an introductory tutorial designed for beginners to help them understand the basics of Radius.

About the Tutorial. Audience. Prerequisites. Copyright and Disclaimer. Logstash

Memcached is an open source, high-performance, distributed memory object caching system.

About the Tutorial. Audience. Prerequisites. Copyright and Disclaimer. PySpark

This tutorial also elaborates on other related methodologies like Agile, RAD and Prototyping.

This tutorial has been prepared for beginners to help them understand the simple but effective SEO characteristics.

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright DAX

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Graph Theory

This tutorial provides a basic level understanding of the LOLCODE programming language.

Testing is the process of evaluating a system or its component(s) with the intent to find whether it satisfies the specified requirements or not.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming

About Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Euphoria

Parrot is a virtual machine designed to efficiently compile and execute bytecode for interpreted languages.

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Django

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer ASP.NET WP

SAP Lumira is known as a visual intelligence tool that is used to visualize data and create stories to provide graphical details of the data.

This tutorial explains the key concepts of Web Dynpro with relevant screenshots for better understanding.

This tutorial provides a basic understanding of the infrastructure and fundamental concepts of managing an infrastructure using Chef.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Meteor

In this tutorial, we are going to learn how to use the various features available in Flexbox.

This tutorial helps the professionals aspiring to make a career in Big Data and NoSQL databases, especially the documents store.

So, this tutorial is divided into various chapters and describes the 5G technology, its applications, challenges, etc., in detail.

This tutorial will show you, how to use RSpec to test your code when building applications with Ruby.

You should have a basic understanding of Relational concepts and basic SQL. It will be good if you have worked with any other RDBMS product.

Before you start with this tutorial, you need to know basic Java programming.

Scalable Vector Graphics commonly known as SVG is a XML based format to draw vector images. It is used to draw twodimentional vector images.

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. TurboGears

jmeter is an open source testing software. It is 100% pure Java application for load and performance testing.

This tutorial is designed for software programmers who would like to learn the basics of ASP.NET Core from scratch.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Drupal

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Gerrit

This tutorial will guide users on how to utilize TestLodge in reporting and maintaining the testing activities.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. WordPress

This tutorial is designed for all Java enthusiasts who want to learn document type detection and content extraction using Apache Tika.

This tutorial will take you through simple and practical approaches while learning AOP framework provided by Spring.

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Jenkins

In mainframe environment, programs can be executed in batch and online modes. JCL is used for submitting a program for execution in batch mode.

In this brief tutorial, we will be explaining the basics of Elasticsearch and its features.

This tutorial provides a basic understanding of how to generate professional reports using Pentaho Report Designer.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer DBMS

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. HCatalog

This tutorial covers a foundational understanding of IPC. Each of the chapters contain related topics with simple and useful examples.

Linux Essentials. Smith, Roderick W. Table of Contents ISBN-13: Introduction xvii. Chapter 1 Selecting an Operating System 1

This tutorial has been designed for beginners interested in learning the basic concepts of UDDI.

This tutorial is designed for those who would like to understand the basics of i-mode in simple and easy steps.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Before proceeding with this tutorial, you should have a good understanding of the fundamental concepts of marketing.

This tutorial will help you understand JSON and its use within various programming languages such as PHP, PERL, Python, Ruby, Java, etc.

This is an introductory tutorial, which covers the basics of Jython and explains how to handle its various modules and sub-modules.

This tutorial will teach you how to use Java Servlets to develop your web based applications in simple and easy steps.

Before you start proceeding with this tutorial, we are assuming that you are already aware about the basics of Web development.

This tutorial has been prepared for computer science graduates to help them understand the basic-to-advanced concepts related to data mining.

In this tutorial, we will discuss the architecture, pin diagram and other key concepts of microprocessors.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Joomla

This tutorial is prepared for beginners to help them understand the basic-to-advanced concepts related to GPRS.

This tutorial will help you in understanding IPv4 and its associated terminologies along with appropriate references and examples.

This tutorial will give you a quick start with Consul and make you comfortable with its various components.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. RichFaces

Microsoft Excel is a spreadsheet tool capable of performing calculations, analyzing data and integrating information from different programs.

Dart is an open-source general-purpose programming language. It is originally developed by Google and later approved as a standard by ECMA.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Laravel

This is a small tutorial where we will cover all the basic steps needed to start with Balsamiq Mockups.

Before proceeding with this tutorial, you must have a good understanding of Core Java and any of the Linux flavors.

This tutorial introduces you to key DynamoDB concepts necessary for creating and deploying a highly-scalable and performance-focused database.

Data Manipulation with AWK. Evangelos Pournaras, Izabela Moise

This tutorial explains how you can use Gradle as a build automation tool for Java as well as Groovy projects.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

This is a simple tutorial that covers the basics of SAP Business Intelligence and how to handle its various other components.

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright CICS

CS Unix Tools & Scripting

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Apache Bench

This tutorial will help computer science graduates to understand the basic-to-advanced concepts related to data warehousing.

Learn C programme. C Programming language. Cloud1 C tutorial

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Avro

If you are a software developer, system administrator, or a GNU/Linux loving person, then this tutorial is for you.

Linux Fundamentals (L-120)

LINUX FUNDAMENTALS. Supported Distributions: Red Hat Enterprise Linux 6 SUSE Linux Enterprise 11 Ubuntu LTS. Recommended Class Length: 5 days

This tutorial is meant for software developers who want to learn how to lose less time on API integrations!

Prerequisites: Students should be comfortable with computers. No familiarity with Linux or other Unix operating systems is required.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Manual Shell Script Linux If Not Equal String Comparison

Adobe Flex Tutorial i

This tutorial discusses the basics of PouchDB along with relevant examples for easy understanding.

1Z Oracle Linux Fundamentals (Oracle Partner Network) Exam Summary Syllabus Questions

Memcached is an open source, high-performance, distributed memory object caching system.

Lecture #13 AWK Part I (Chapter 6)

ITEXT. [Document subtitle]

STREAM EDITOR - QUICK GUIDE STREAM EDITOR - OVERVIEW

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.

This tutorial covers various topics ranging from the basics of Lua to its scope in various applications.

Shell Script Programming 2

Unzip command in unix

Linux shell & shell scripting - II

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

The student will have the essential skills needed to be proficient at the Unix or Linux command line.

LINUX FUNDAMENTALS (5 Day)

This tutorial has been designed to help beginners understand the basic concepts of WiMAX.

Transcription:

i

About the Tutorial This tutorial takes you through AWK, one of the most prominent text-processing utility on GNU/Linux. It is very powerful and uses simple programming language. It can solve complex text processing tasks with a few lines of code. Starting with an overview of AWK, its environment, and workflow, the tutorial proceeds to explain the syntax, variables, operators, arrays, loops, and functions used in AWK. It also covers topics such as output redirection and pretty printing. Audience This tutorial will be useful for software developers, system administrators, or any enthusiastic reader inclined to learn how to do text processing and data extraction in Unix-like environment. Prerequisites You must have a basic understanding of GNU/Linux operating system and shell scripting. Copyright & Disclaimer Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@tutorialspoint.com i

Table of Contents About the Tutorial... i Audience... i Prerequisites... i Copyright & Disclaimer... i Table of Contents... ii 1. OVERVIEW... 1 Types of AWK... 1 Typical Uses of AWK... 1 2. AWK ENVIRONMENT... 2 Installation Using Package Manager... 2 Installation from Source Code... 2 3. AWK WORKFLOW... 4 Program Structure... 5 Example... 5 4. BASIC SYNTAX... 7 AWK Command Line... 7 AWK Program File... 7 AWK Standard Options... 8 5. BASIC EXAMPLES... 13 Printing Column or Field... 13 Printing All Lines... 13 Printing Columns by Pattern... 14 Printing Column in Any Order... 14 Counting and Printing Matched Pattern... 14 Printing Lines with More than 18 Characters... 15 ii

6. BUILT-IN VARIABLES... 16 Standard AWK Variables... 16 GNU AWK Specific Variables... 20 7. OPERATORS... 23 Arithmetic Operators... 23 Increment and Decrement Operators... 24 Assignment Operators... 25 Relational Operators... 27 Logical Operators... 29 Ternary Operator... 30 Unary Operators... 31 Exponential Operators... 31 String Concatenation Operator... 32 Array Membership Operator... 32 Regular Expression Operators... 32 8. REGULAR EXPRESSIONS... 34 Dot... 34 Start of Line... 34 End of Line... 34 Match Character Set... 35 Exclusive Set... 35 Alteration... 35 Zero or One Occurrence... 36 Zero or More Occurrence... 36 One or More Occurrence... 36 Grouping... 37 iii

9. ARRAYS... 38 Creating Array... 38 Deleting Array Elements... 38 Multi-Dimensional Arrays... 39 10. CONTROL FLOW... 41 If Statement... 41 If-Else Statement... 41 If-Else-If Ladder... 42 11. LOOPS... 43 For Loop... 43 While Loop... 43 Do-While Loop... 44 Break Statement... 44 Continue Statement... 45 Exit Statement... 46 12. BUILT-IN FUNCTIONS... 47 Arithmetic Functions... 47 String Functions... 51 Time Functions... 57 Bit Manipulation Functions... 60 Miscellaneous Functions... 62 13. USER-DEFINED FUNCTIONS... 68 14. OUTPUT REDIRECTION... 70 Redirection Operator... 70 Append Operator... 70 Pipe... 71 iv

Two-Way Communication... 71 15. PRETTY PRINTING... 73 Escape Sequences... 73 Format Specifier... 75 Optional Parameters with %... 78 v

1. OVERVIEW AWK AWK is an interpreted programming language. It is very powerful and specially designed for text processing. Its name is derived from the family names of its authors Alfred Aho, Peter Weinberger, and Brian Kernighan. The version of AWK that GNU/Linux distributes is written and maintained by the Free Software Foundation (FSF); it is often referred to as GNU AWK. Types of AWK Following are the variants of AWK: AWK - Original AWK from AT & T Laboratory. NAWK - Newer and improved version of AWK from AT & T Laboratory. GAWK - It is GNU AWK. All GNU/Linux distributions ship GAWK. It is fully compatible with AWK and NAWK. Typical Uses of AWK Myriad of tasks can be done with AWK. Listed below are just a few of them: Text processing Producing formatted text reports Performing arithmetic operations Performing string operations, and many more 6

2. AWK ENVIRONMENT AWK This chapter describes how to set up the AWK environment on your GNU/Linux system. Installation Using Package Manager Generally, AWK is available by default on most GNU/Linux distributions. You can use which command to check whether it is present on your system or not. In case you don t have AWK, then install it on Debian based GNU/Linux using Advance Package Tool (APT) package manager as follows: [jeryy]$ sudo apt-get update [jeryy]$ sudo apt-get install gawk Similarly, to install AWK on RPM based GNU/Linux, use Yellowdog Updator Modifier (YUM) package manager as follows: [root]# yum install gawk After installation, ensure that AWK is accessible via command line. [jerry]$ which awk On executing the above code, you get the following result: /usr/bin/awk Installation from Source Code As GNU AWK is a part of the GNU project, its source code is available for free download. We have already seen how to install AWK using package manager. Let us now understand how to install AWK from its source code. The following installation is applicable to any GNU/Linux software, and for most other freelyavailable programs as well. Here are the installation steps: Step 1 - Download the source code from an authentic place. The command-line utility wget serves this purpose. [jerry]$ wget http://ftp.gnu.org/gnu/gawk/gawk-4.1.1.tar.xz 7

Step 2 - Decompress and extract the downloaded source code. [jerry]$ tar xvf gawk-4.1.1.tar.xz Step 3 - Change into the directory and run configure. [jerry]$./configure Step 4 - Upon successful completion, the configure generates Makefile. To compile the source code, execute a make command. [jerry]$ make Step 5 - You can run the test suite to ensure the build is clean. This is an optional step. [jerry]$ make check Step 6 - Finally, install AWK. Make sure you have super-user privileges. [jerry]$ sudo make install That is it! You have successfully compiled and installed AWK. Verify it by executing the awk command as follows: [jerry]$ which awk On executing this code, you get the following result: /usr/bin/awk 8

3. AWK WORKFLOW AWK To become an expert AWK programmer, you need to know its internals. AWK follows a simple workflow: Read, Execute, and Repeat. The following diagram depicts the workflow of AWK: Read AWK reads a line from the input stream (file, pipe, or stdin) and stores it in memory. Execute All AWK commands are applied sequentially on the input. By default, AWK executes commands on every line. We can restrict this by providing patterns. Repeat This process repeats until the file reaches its end. 9

End of ebook preview If you liked what you saw Buy it from our store @ https://store.tutorialspoint.com 10