A talk about AWK Don Newcomb 18 Jan 2014. What is AWK? AWK is an interpreted computer language It is primarily used for text processing and data formatting.

Slides:



Advertisements
Similar presentations
CST8177 awk. The awk program is not named after the sea-bird (that's auk), nor is it a cry from a parrot (awwwk!). It's the initials of the authors, Aho,
Advertisements

1 Unix Talk #2 AWK overview Patterns and actions Records and fields Print vs. printf.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 6.
Perl Basics Chapters 1-6 of “Learning Perl” By Randal Schwartz, Tom Christiansen & Larry Wall; ISBN , 302 pages. Second Edition, July 1997.
CSC 4630 Meeting 9 February 14, 2007 Valentine’s Day; Snow Day.
AWK: The Duct Tape of Computer Science Research Tim Sherwood UC Santa Barbara.
AWK: The Duct Tape of Computer Science Research Tim Sherwood UC San Diego.
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Shell Scripting Awk (part1) Awk Programming Language standard unix language that is geared for text processing and creating formatted reports but it.
Agenda Sed Utility - Advanced –Using Script-files / Example Awk Utility - Advanced –Using Script-files –Math calculations / Operators / Functions –Floating.
A Guide to Unix Using Linux Fourth Edition
Nael Alian Introduction to PHP
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
AWK. text processing languge awk Created for Unix by Aho, Weinberger and Kernighan Basicly an: ▫interpreted ▫text processing ▫programming language Updated.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Programming Languages Meeting 13 December 2/3, 2014.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
Introduction to Awk Awk is a convenient and expressive programming language that can be applied to a wide variety of computing and data manipulation tasks.
Programmable Text Processing with awk Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users”
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Exam Revision Ruibin Bai (Room AB326) Division of Computer Science The University of Nottingham.
Awk Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
Sed, awk, & perl CS 2204 Class meeting 13 *Notes by Mir Farooq Ali and other members of the CS faculty at Virginia Tech. Copyright 2003.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Chapter 12: gawk Yes it sounds funny. In this chapter … Intro Patterns Actions Control Structures Putting it all together.
13 More Advanced Awk Mauro Jaskelioff (originally by Gail Hopkins)
Revision Lecture Mauro Jaskelioff. AWK Program Structure AWK programs consists of patterns and procedures Pattern_1 { Procedure_1} Pattern_2 { Procedure_2}
Introduction to Unix – CS 21
BY A Mikati & M Shaito Awk Utility n Introduction n Some basics n Some samples n Patterns & Actions Regular Expressions n Boolean n start /end n.
Time to talk about your class projects!. Shell Scripting Awk (lecture 2)
LIN Unix Lecture 7 Hana Filip. LIN Text Processing Command Line Utility Programs (cont.) sed LAST WEEK wc sort tr uniq awk TODAY join paste.
Getting the most out of the workshop Ask questions!!! Don’t sit next to someone you already know Work with someone with a different skillset and different.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Chapter Twelve sed, awk & perl1 System Programming sed, awk & perl.
Chapter Six Introduction to Shell Script Programming.
© 2006 KDnuggets [16/Nov/2005:16:32: ] "GET /jobs/ HTTP/1.1" "
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
16-Dec-15Advanced Programming Spring 2002 sed and awk Henning Schulzrinne Dept. of Computer Science Columbia University.
CSCI 330 UNIX and Network Programming
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
1 P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Awk Programming Ruibin Bai (Room AB326) Division of Computer Science The University.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Awk Programming (3) Ruibin Bai (Room AB326) Division of Computer Science The University.
Alon Efrat Computer Science Department University of Arizona Unix Tools.
CISC 1480/KRF Copyright © 1999 by Kenneth R. Frazer 1 AWK q A programming language for handling common data manipulation tasks with only a few lines of.
Sed. Class Issues vSphere Issues – root only until lab 3.
1 Lecture 10 Introduction to AWK COP 3344 Introduction to UNIX.
By Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 13 Scott Marino.
Programming Languages Meeting 12 November 18/19, 2014.
Awk 2 – more awk. AWK INVOCATION AND OPERATION the "-F" option allows changing Awk's "field separator" character. Awk regards each line of input data.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Arun Vishwanathan Nevis Networks Pvt. Ltd.
AWK.
CSC 4630 Meeting 7 February 7, 2007.
Kevin Taylor.
PROGRAMMING THE BASH SHELL PART IV by İlker Korkmaz and Kaya Oğuz
CS 403: Programming Languages
What is Bash Shell Scripting?
John Carelli, Instructor Kutztown University
Guide To UNIX Using Linux Third Edition
Programming Languages
Awk.
Presentation transcript:

A talk about AWK Don Newcomb 18 Jan 2014

What is AWK? AWK is an interpreted computer language It is primarily used for text processing and data formatting. Very handy for one-time data conversion scripts or command-line data manipulation

AWK History Developed at Bell Labs in the ’70s and named for its authors Aho, Weinberger and Kernighan. Awk sounded better than Wak or Kaw. Homonym with auk, the name of a bird, so is original part of the Unix menagerie. Part of original Unix software suite for formatting telephone directories. Many flavors, variations and extensions in 40 years. Gnu-AWK (GAWK) commonly used in Linux.

Basics: Fields, patterns & actions AWK looks at a text file as a series of records (lines) made up of fields. Default field separator is white space and line separator is LF. Checks each line for a matching the pattern. Blank pattern is always matched. When a pattern is matched the defined action is taken. Pattern precedes the action, which is enclosed in curly braces {}. ' pattern { action }' Patterns can be regular expressions

Simple examples awk < file ‘{print $3, $1}’ echo 42 | awk '{ print ($1-32)*(5/9) }‘ awk ' /^bozon/ { print $4 + $7 }' awk < words '/^water/ {print $1}' awk '/water$/ {print $1}' words awk 'BEGIN{print "Hello, World"}'

Varables Variables are defined when assigned. (e.g. x=0.3, name="Don") Predefined variables include $1, $2,,,,$0, NF, $NF, FS, RS Arrays are associative tables: –french["cat"] = "chat" –french["dog"] = "chien"

Iteration anyone? awk '{ tot=0; for (i=1; i<=NF; i++) tot += $i; printtot/NF; }' file awk '{ if ( $1 == "parse") print $0}' words { if (x % 2 == 0) print "x is even"; else print "x is odd"} while, do-while, switch & break also exist

More on patterns There are some special patterns, BEGIN and END. They match the record before the first record and after the last one. In other words, the BEGIN action is run at the start of the program and the END action is run after the EOF is encountered. Two patterns separated by a coma includes all records from the the first match of pattern 1 to the first match of pattern 2. Patterns can be expressions.

Example awk < words '/^parse/,/^parsley/{print $0}' awk < words '/parse/,/parsley/{print $0}' awk < words ' $1 ~ /parse/ {print $0}' awk < words ' $1 == "parse" {print $0}'

Trivia Awk is most often used for one line, throw away scripts but some interesting things have been done using the language. Henry Spencer wrote "The Amazing Awk Assembler" (aaa) entirely in awk and sed. It converts assembly language for the old Motorola 68XX chips into machine code.